ZQuest Classic Coverage Report


Directory: src/
File: src/zc/script_drawing.cpp
Date: 2025-01-13 08:29:44
Exec Total Coverage
Lines: 1360 5628 24.2%
Functions: 49 105 46.7%
Branches: 583 2861 20.4%

Line Branch Exec Source
1 //! ritate_sprite_trans doesn't seem to be supported by or allegro header !?
2
3 //glibc 2.28 and later require this: -Z
4 #ifdef __GNUG__
5 #define ALLEGRO_NO_FIX_ALIASES
6 #endif
7
8 #include "base/qrs.h"
9 #include "base/dmap.h"
10 #include "base/zc_alleg.h"
11 #include "zc/script_drawing.h"
12 #include "zc/rendertarget.h"
13 #include "zc/maps.h"
14 #include "tiles.h"
15 #include "zc/zelda.h"
16 #include "zc/ffscript.h"
17 #include "base/util.h"
18 #include "subscr.h"
19 #include "drawing.h"
20 #include "base/mapscr.h"
21 #include "base/misctypes.h"
22 using namespace util;
23 extern ZModule zcm;
24 extern refInfo *ri;
25 extern script_bitmaps scb;
26 #include <stdio.h>
27 #include <fstream>
28
29 #define DegtoFix(d) ((d)*0.7111111111111)
30 #define RadtoFix(d) ((d)*40.743665431525)
31
32 inline double sd_log2( double n )
33 {
34 // log(n)/log(2) is log2.
35 double v = log( (double)n ) / log( (double)2 );
36 return v;
37 }
38
39 inline bool isPowerOfTwo(int32_t n)
40 {
41 if(n==0)
42 return false;
43
44 return (ceil(sd_log2(n)) == floor(sd_log2(n)));
45 }
46
47
48
49 template<class T> inline
50 241609 fixed degrees_to_fixed(T d)
51 {
52 241609 return ftofix(DegtoFix(d));
53 }
54 template<class T> inline
55 fixed radians_to_fixed(T d)
56 {
57 return ftofix(RadtoFix(d));
58 }
59
60 BITMAP* ScriptDrawingBitmapPool::_parent_bmp = 0;
61
62 class TileHelper
63 {
64 public:
65
66 46094 static void OldPutTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
67 {
68 // Past the end of the tile page?
69
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46094 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46094 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
70 {
71 byte w2=(tile+w)%TILES_PER_ROW;
72 OldPutTile(_Dest, tile, x, y, w-w2, h, color, flip);
73 OldPutTile(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip);
74 return;
75 }
76
77
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 46094 times.
46094 switch(flip)
78 {
79 case 1:
80 for(int32_t j=0; j<h; j++)
81 for(int32_t k=w-1; k>=0; k--)
82 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip);
83
84 break;
85
86 case 2:
87 for(int32_t j=h-1; j>=0; j--)
88 for(int32_t k=0; k<w; k++)
89 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip);
90
91 break;
92
93 case 3:
94 for(int32_t j=h-1; j>=0; j--)
95 for(int32_t k=w-1; k>=0; k--)
96 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip);
97
98 break;
99
100 46094 case 0:
101 default:
102
2/2
✓ Branch 0 taken 181240 times.
✓ Branch 1 taken 46094 times.
227334 for(int32_t j=0; j<h; j++)
103
2/2
✓ Branch 0 taken 1111148 times.
✓ Branch 1 taken 181240 times.
1292388 for(int32_t k=0; k<w; k++)
104 1292388 oldputtile16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip);
105
106 46094 break;
107 }
108 46094 }
109
110 3798249 static void OverTile(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, byte skiprows=0)
111 {
112 3798249 overtileblock16(_Dest,tile,x,y,w,h,color,flip,skiprows);
113 3798249 }
114
115 static void OverTileCloaked(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t flip, byte skiprows=0)
116 {
117 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
118 {
119 byte w2=(tile+w)%TILES_PER_ROW;
120 OverTileCloaked(_Dest, tile, x, y, w-w2, h, flip);
121 OverTileCloaked(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, flip);
122 return;
123 }
124
125 switch(flip)
126 {
127 case 1:
128 for(int32_t j=0; j<h; j++)
129 for(int32_t k=w-1; k>=0; k--)
130 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, flip);
131
132 break;
133
134 case 2:
135 for(int32_t j=h-1; j>=0; j--)
136 for(int32_t k=0; k<w; k++)
137 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, flip);
138
139 break;
140
141 case 3:
142 for(int32_t j=h-1; j>=0; j--)
143 for(int32_t k=w-1; k>=0; k--)
144 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, flip);
145
146 break;
147
148 default:
149 for(int32_t j=0; j<h; j++)
150 for(int32_t k=0; k<w; k++)
151 overtilecloaked16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, flip);
152
153 break;
154 }
155 }
156
157 285572 static void OverTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
158 {
159
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 285572 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
285572 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
160 {
161 byte w2=(tile+w)%TILES_PER_ROW;
162 OverTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
163 OverTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
164 return;
165 }
166
167
1/4
✓ Branch 0 taken 285572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
285572 switch(flip)
168 {
169 case 1:
170 for(int32_t j=0; j<h; j++)
171 for(int32_t k=w-1; k>=0; k--)
172 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
173
174 break;
175
176 case 2:
177 for(int32_t j=h-1; j>=0; j--)
178 for(int32_t k=0; k<w; k++)
179 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
180
181 break;
182
183 case 3:
184 for(int32_t j=h-1; j>=0; j--)
185 for(int32_t k=w-1; k>=0; k--)
186 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
187
188 break;
189
190 default:
191
2/2
✓ Branch 0 taken 1666190 times.
✓ Branch 1 taken 285572 times.
1951762 for(int32_t j=0; j<h; j++)
192
2/2
✓ Branch 0 taken 23539931 times.
✓ Branch 1 taken 1666190 times.
25206121 for(int32_t k=0; k<w; k++)
193 25206121 overtiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
194
195 285572 break;
196 }
197 285572 }
198
199 static void PutTileTranslucent(BITMAP* _Dest, int32_t tile, int32_t x, int32_t y, int32_t w, int32_t h, int32_t color, int32_t flip, int32_t opacity, byte skiprows=0)
200 {
201 if(skiprows>0 && tile%TILES_PER_ROW+w>=TILES_PER_ROW)
202 {
203 byte w2=(tile+w)%TILES_PER_ROW;
204 PutTileTranslucent(_Dest, tile, x, y, w-w2, h, color, flip, opacity);
205 PutTileTranslucent(_Dest, tile+(w-w2)+(skiprows*TILES_PER_ROW), x+16*(w-w2), y, w2, h, color, flip, opacity);
206 return;
207 }
208
209 switch(flip)
210 {
211 case 1:
212 for(int32_t j=0; j<h; j++)
213 for(int32_t k=w-1; k>=0; k--)
214 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+j*16, color, flip, opacity);
215
216 break;
217
218 case 2:
219 for(int32_t j=h-1; j>=0; j--)
220 for(int32_t k=0; k<w; k++)
221 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+((h-1)-j)*16, color, flip, opacity);
222
223 break;
224
225 case 3:
226 for(int32_t j=h-1; j>=0; j--)
227 for(int32_t k=w-1; k>=0; k--)
228 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+((w-1)-k)*16, y+((h-1)-j)*16, color, flip, opacity);
229
230 break;
231
232 default:
233 for(int32_t j=0; j<h; j++)
234 for(int32_t k=0; k<w; k++)
235 puttiletranslucent16(_Dest, tile+(j*TILES_PER_ROW)+k, x+k*16, y+j*16, color, flip, opacity);
236
237 break;
238 }
239 }
240 };
241
242
243
244
245 2364821 void do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
246 {
247 //sdci[1]=layer
248 //sdci[2]=x
249 //sdci[3]=y
250 //sdci[4]=x2
251 //sdci[5]=y2
252 //sdci[6]=color
253 //sdci[7]=scale factor
254 //sdci[8]=rotation anchor x
255 //sdci[9]=rotation anchor y
256 //sdci[10]=rotation angle
257 //sdci[11]=fill
258 //sdci[12]=opacity
259
1/2
✓ Branch 0 taken 2364821 times.
✗ Branch 1 not taken.
2364821 if(sdci[7]==0) //scale
260 {
261 return;
262 }
263
264 2364821 int32_t x1=sdci[2]/10000;
265 2364821 int32_t y1=sdci[3]/10000;
266 2364821 int32_t x2=sdci[4]/10000;
267 2364821 int32_t y2=sdci[5]/10000;
268
269
1/2
✓ Branch 0 taken 2364821 times.
✗ Branch 1 not taken.
2364821 if(x1>x2)
270 {
271 zc_swap(x1,x2);
272 }
273
274
2/2
✓ Branch 0 taken 2345305 times.
✓ Branch 1 taken 19516 times.
2364821 if(y1>y2)
275 {
276 19516 zc_swap(y1,y2);
277 19516 }
278
279
2/2
✓ Branch 0 taken 2363144 times.
✓ Branch 1 taken 1677 times.
2364821 if(sdci[7] != 10000)
280 {
281 1677 int32_t w=x2-x1+1;
282 1677 int32_t h=y2-y1+1;
283 1677 int32_t w2=(w*sdci[7])/10000;
284 1677 int32_t h2=(h*sdci[7])/10000;
285 1677 x1=x1-((w2-w)/2);
286 1677 x2=x2+((w2-w)/2);
287 1677 y1=y1-((h2-h)/2);
288 1677 y2=y2+((h2-h)/2);
289 1677 }
290
291 2364821 int32_t color=sdci[6]/10000;
292
293
2/2
✓ Branch 0 taken 2328342 times.
✓ Branch 1 taken 36479 times.
2364821 if(sdci[12]/10000<=127) //translucent
294 {
295 36479 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
296 36479 }
297
298
2/2
✓ Branch 0 taken 82060 times.
✓ Branch 1 taken 2282761 times.
2364821 if(sdci[10]==0) //no rotation
299 {
300
2/2
✓ Branch 0 taken 733585 times.
✓ Branch 1 taken 1549176 times.
2282761 if(sdci[11]) //filled
301 {
302 1549176 rectfill(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
303 1549176 }
304 else //outline
305 {
306 733585 rect(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
307 }
308 2282761 }
309 else //rotate
310 {
311 int32_t xy[16];
312 82060 int32_t rx=sdci[8]/10000;
313 82060 int32_t ry=sdci[9]/10000;
314 82060 fixed ra1=itofix(sdci[10]%10000)/10000;
315 82060 fixed ra2=itofix(sdci[10]/10000);
316 82060 fixed ra=ra1+ra2;
317 82060 ra = (ra/360)*256;
318
319 82060 fixed fcosa = fixcos(ra);
320 82060 fixed fsina = fixsin(ra);
321
322 82060 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
323 82060 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
324 82060 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
325 82060 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
326 82060 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
327 82060 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
328 82060 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
329 82060 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
330 82060 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
331 82060 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
332 82060 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
333 82060 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
334 82060 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
335 82060 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
336 82060 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
337 82060 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
338
339
1/2
✓ Branch 0 taken 82060 times.
✗ Branch 1 not taken.
82060 if(sdci[11]) //filled
340 {
341 82060 polygon(bmp, 4, xy, color);
342 82060 }
343 else //outline
344 {
345 line(bmp, xy[0], xy[1], xy[10], xy[11], color);
346 line(bmp, xy[2], xy[3], xy[12], xy[13], color);
347 line(bmp, xy[4], xy[5], xy[14], xy[15], color);
348 line(bmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
349 }
350 }
351
352 2364821 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
353 2364821 }
354
355 void do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
356 {
357 //sdci[1]=layer
358 //sdci[2]=x
359 //sdci[3]=y
360 //sdci[4]=tile
361 //sdci[5]=cset
362 //sdci[6]=width
363 //sdci[7]=height
364 //sdci[8]=overlay
365 //sdci[9]=opacity
366
367 int32_t x=sdci[2]/10000;
368 int32_t y=sdci[3]/10000;
369
370 int32_t tile=sdci[4]/10000;
371 int32_t cs=sdci[5]/10000;
372 int32_t w=sdci[6]/10000;
373 int32_t h=sdci[7]/10000;
374 bool overlay=sdci[8];
375 bool trans=(sdci[9]/10000<=127);
376
377 frame2x2(bmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
378 }
379
380
381
382 1130854 void do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
383 {
384 //sdci[1]=layer
385 //sdci[2]=x
386 //sdci[3]=y
387 //sdci[4]=radius
388 //sdci[5]=color
389 //sdci[6]=scale factor
390 //sdci[7]=rotation anchor x
391 //sdci[8]=rotation anchor y
392 //sdci[9]=rotation angle
393 //sdci[10]=fill
394 //sdci[11]=opacity
395
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6]==0) //scale
396 {
397 return;
398 }
399
400 1130854 int32_t x1=sdci[2]/10000;
401 1130854 int32_t y1=sdci[3]/10000;
402 1130854 qword r=sdci[4];
403
404
1/2
✓ Branch 0 taken 1130854 times.
✗ Branch 1 not taken.
1130854 if(sdci[6] != 10000)
405 {
406 r*=sdci[6];
407 r/=10000;
408 }
409
410 1130854 r/=10000;
411 1130854 int32_t color=sdci[5]/10000;
412
413
2/2
✓ Branch 0 taken 959832 times.
✓ Branch 1 taken 171022 times.
1130854 if(sdci[11]/10000<=127) //translucent
414 {
415 171022 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
416 171022 }
417
418
5/6
✓ Branch 0 taken 58575 times.
✓ Branch 1 taken 1072279 times.
✓ Branch 2 taken 1344 times.
✓ Branch 3 taken 57231 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1344 times.
1130854 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
419 {
420 int32_t xy[2];
421 57231 int32_t rx=sdci[7]/10000;
422 57231 int32_t ry=sdci[8]/10000;
423 57231 fixed ra1=itofix(sdci[9]%10000)/10000;
424 57231 fixed ra2=itofix(sdci[9]/10000);
425 57231 fixed ra=ra1+ra2;
426 57231 ra = (ra/360)*256;
427
428 57231 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
429 57231 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
430 57231 x1=xy[0];
431 57231 y1=xy[1];
432 57231 }
433
434
2/2
✓ Branch 0 taken 1113840 times.
✓ Branch 1 taken 17014 times.
1130854 if(sdci[10]) //filled
435 {
436 1113840 circlefill(bmp, x1+xoffset, y1+yoffset, r, color);
437 1113840 }
438 else //outline
439 {
440 17014 circle(bmp, x1+xoffset, y1+yoffset, r, color);
441 }
442
443 1130854 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
444 1130854 }
445
446
447 void do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
448 {
449 //sdci[1]=layer
450 //sdci[2]=x
451 //sdci[3]=y
452 //sdci[4]=radius
453 //sdci[5]=start angle
454 //sdci[6]=end angle
455 //sdci[7]=color
456 //sdci[8]=scale factor
457 //sdci[9]=rotation anchor x
458 //sdci[10]=rotation anchor y
459 //sdci[11]=rotation angle
460 //sdci[12]=closed
461 //sdci[13]=fill
462 //sdci[14]=opacity
463
464 if(sdci[8]==0) //scale
465 {
466 return;
467 }
468
469 int32_t cx=sdci[2]/10000;
470 int32_t cy=sdci[3]/10000;
471 qword r=sdci[4];
472
473 if(sdci[8] != 10000)
474 {
475 r*=sdci[8];
476 r/=10000;
477 }
478
479 r/=10000;
480
481 int32_t color=sdci[7]/10000;
482
483 fixed ra1=itofix(sdci[11]%10000)/10000;
484 fixed ra2=itofix(sdci[11]/10000);
485 fixed ra=ra1+ra2;
486 ra = (ra/360)*256;
487
488
489 fixed a1=itofix(sdci[5]%10000)/10000;
490 fixed a2=itofix(sdci[5]/10000);
491 fixed sa=a1+a2;
492 sa = (sa/360)*256;
493
494 a1=itofix(sdci[6]%10000)/10000;
495 a2=itofix(sdci[6]/10000);
496 fixed ea=a1+a2;
497 ea = (ea/360)*256;
498
499 if(sdci[11]!=0) //rotation
500 {
501 int32_t rx=sdci[9]/10000;
502 int32_t ry=sdci[10]/10000;
503
504 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
505 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
506 ea-=ra;
507 sa-=ra;
508 }
509
510 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
511 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
512
513 if(sdci[12]) //closed
514 {
515 if(sdci[13]) //filled
516 {
517 clear_bitmap(prim_bmp);
518 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
519 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
520 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
521 int fillx = zc_max(0,fx)+xoffset;
522 int filly = zc_max(0,fy)+yoffset;
523 zprint2("Screen->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
524 floodfill(prim_bmp, fillx, filly, color);
525
526 if(sdci[14]/10000<=127) //translucent
527 {
528 draw_trans_sprite(bmp, prim_bmp, 0,0);
529 }
530 else
531 {
532 draw_sprite(bmp, prim_bmp, 0,0);
533 }
534 }
535 else
536 {
537 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
538 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
539 line(bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
540 }
541 }
542 else
543 {
544 if(sdci[14]/10000<=127) //translucent
545 {
546 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
547 }
548
549 arc(bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
550 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
551 }
552 }
553
554
555 1850 void do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
556 {
557 //sdci[1]=layer
558 //sdci[2]=x
559 //sdci[3]=y
560 //sdci[4]=radiusx
561 //sdci[5]=radiusy
562 //sdci[6]=color
563 //sdci[7]=scale factor
564 //sdci[8]=rotation anchor x
565 //sdci[9]=rotation anchor y
566 //sdci[10]=rotation angle
567 //sdci[11]=fill
568 //sdci[12]=opacity
569
570
1/2
✓ Branch 0 taken 1850 times.
✗ Branch 1 not taken.
1850 if(sdci[7]==0) //scale
571 {
572 return;
573 }
574
575 1850 int32_t x1=sdci[2]/10000;
576 1850 int32_t y1=sdci[3]/10000;
577 1850 int32_t radx=sdci[4]/10000;
578 1850 radx*=sdci[7]/10000;
579 1850 int32_t rady=sdci[5]/10000;
580 1850 rady*=sdci[7]/10000;
581 1850 int32_t color=sdci[6]/10000;
582 1850 float rotation = sdci[10]/10000;
583
584 1850 int32_t rx=sdci[8]/10000;
585 1850 int32_t ry=sdci[9]/10000;
586 1850 fixed ra1=itofix(sdci[10]%10000)/10000;
587 1850 fixed ra2=itofix(sdci[10]/10000);
588 1850 fixed ra=ra1+ra2;
589 1850 ra = (ra/360)*256;
590
591 int32_t xy[2];
592 1850 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
593 1850 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
594 1850 x1=xy[0];
595 1850 y1=xy[1];
596
597
6/8
✓ Branch 0 taken 1746 times.
✓ Branch 1 taken 104 times.
✓ Branch 2 taken 1687 times.
✓ Branch 3 taken 59 times.
✓ Branch 4 taken 1687 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1687 times.
1850 if(radx<1||rady<1||radx>255||rady>255) return;
598
599 1687 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
600
601
2/2
✓ Branch 0 taken 1630 times.
✓ Branch 1 taken 57 times.
1687 if(sdci[11]) //filled
602 {
603
604
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 606 times.
1630 if(sdci[12]/10000<128) //translucent
605 {
606 1024 clear_bitmap(prim_bmp);
607
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
608 1024 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
609 1024 draw_trans_sprite(bmp, prim_bmp, 0, 0);
610 1024 }
611 else // no opacity
612 {
613
1/2
✓ Branch 0 taken 606 times.
✗ Branch 1 not taken.
606 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
614 606 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
615 }
616 1630 }
617 else //not filled
618 {
619
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 43 times.
57 if(sdci[12]/10000<128) //translucent
620 {
621 14 clear_bitmap(prim_bmp);
622
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
623 14 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
624 14 draw_trans_sprite(bmp, prim_bmp, 0, 0);
625 14 }
626 else // no opacity
627 {
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 43 times.
43 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
629 43 rotate_sprite(bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
630 }
631 }
632
633 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
634 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
635 // the ellipse, but it shouldn't be used anyway.
636
1/2
✓ Branch 0 taken 1687 times.
✗ Branch 1 not taken.
1687 if(color==0)
637 {
638 // This is very slow, so check the smallest possible square
639 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
640 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
641
642 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
643 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
644 if(getpixel(bmp, x, y)==255)
645 putpixel(bmp, x, y, 0);
646 }
647
648 1687 script_drawing_commands.ReleaseSubBitmap(bitty);
649 1850 }
650
651
652 2349855 void do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
653 {
654 //sdci[1]=layer
655 //sdci[2]=x
656 //sdci[3]=y
657 //sdci[4]=x2
658 //sdci[5]=y2
659 //sdci[6]=color
660 //sdci[7]=scale factor
661 //sdci[8]=rotation anchor x
662 //sdci[9]=rotation anchor y
663 //sdci[10]=rotation angle
664 //sdci[11]=opacity
665
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[7]==0) //scale
666 {
667 return;
668 }
669
670 2349855 int32_t x1=sdci[2]/10000;
671 2349855 int32_t y1=sdci[3]/10000;
672 2349855 int32_t x2=sdci[4]/10000;
673 2349855 int32_t y2=sdci[5]/10000;
674
675
2/2
✓ Branch 0 taken 1901533 times.
✓ Branch 1 taken 448322 times.
2349855 if(sdci[7] != 10000)
676 {
677 448322 int32_t w=x2-x1+1;
678 448322 int32_t h=y2-y1+1;
679 448322 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
680 448322 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
681 448322 x1=x1-((w2-w)/2);
682 448322 x2=x2+((w2-w)/2);
683 448322 y1=y1-((h2-h)/2);
684 448322 y2=y2+((h2-h)/2);
685 448322 }
686
687 2349855 int32_t color=sdci[6]/10000;
688
689
1/2
✓ Branch 0 taken 2349855 times.
✗ Branch 1 not taken.
2349855 if(sdci[11]/10000<=127) //translucent
690 {
691 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
692 }
693
694
2/2
✓ Branch 0 taken 937839 times.
✓ Branch 1 taken 1412016 times.
2349855 if(sdci[10]!=0) //rotation
695 {
696 int32_t xy[4];
697 1412016 int32_t rx=sdci[8]/10000;
698 1412016 int32_t ry=sdci[9]/10000;
699 1412016 fixed ra1=itofix(sdci[10]%10000)/10000;
700 1412016 fixed ra2=itofix(sdci[10]/10000);
701 1412016 fixed ra=ra1+ra2;
702
703 1412016 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
704 1412016 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
705 1412016 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
706 1412016 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
707 1412016 x1=xy[0];
708 1412016 y1=xy[1];
709 1412016 x2=xy[2];
710 1412016 y2=xy[3];
711 1412016 }
712
713 2349855 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
714 2349855 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
715 2349855 }
716
717 void do_linesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
718 {
719 //sdci[1]=layer
720 //sdci[2]=array[10] = { x, y, x2, y2, colour, scale, rx, ry, angle, opacity }
721
722 //sdci[2]=x
723 //sdci[3]=y
724 //sdci[4]=x2
725 //sdci[5]=y2
726 //sdci[6]=color
727 //sdci[7]=scale factor
728 //sdci[8]=rotation anchor x
729 //sdci[9]=rotation anchor y
730 //sdci[10]=rotation angle
731 //sdci[11]=opacity
732 //if(sdci[7]==0) //scale
733 //{
734 // return;
735 //}
736
737 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
738
739 if(!v_ptr)
740 {
741 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
742 return;
743 }
744
745 std::vector<int32_t> &v = *v_ptr;
746
747 if(v.empty())
748 return;
749 //Z_scripterrlog("PutPixels reached line %d\n", 983);
750
751 int32_t* pos = &v[0];
752 int32_t sz = v.size();
753
754 for ( int32_t q = 0; q < sz; q+=10 )
755 {
756
757 int32_t x1 = v.at(q);
758 //Z_scripterrlog("Lines( x1 ) is: %d\n", x1);
759 int32_t y1 = v.at(q+1);
760 //Z_scripterrlog("Lines( x2 ) is: %d\n", y1);
761 int32_t x2 = v.at(q+2);
762 //Z_scripterrlog("Lines( x2 ) is: %d\n", x2);
763 int32_t y2 = v.at(q+3);
764 //Z_scripterrlog("Lines( y2 ) is: %d\n", y2);
765 int32_t color = v.at(q+4);
766 //Z_scripterrlog("Lines( colour ) is: %d\n", color);
767 //Z_scripterrlog("Lines( scale ) is: %d\n", v.at(q+5));
768 if (v.at(q+5) == 0) { Z_scripterrlog("Lines() aborting due to scale\n"); return; }//scale
769
770 if( v.at(q+5) != 10000)
771 {
772 int32_t w=x2-x1+1;
773 int32_t h=y2-y1+1;
774 int32_t w2=int32_t(w*((double)v.at(q+5)));
775 int32_t h2=int32_t(h*((double)v.at(q+5)));
776 x1=x1-((w2-w)/2);
777 x2=x2+((w2-w)/2);
778 y1=y1-((h2-h)/2);
779 y2=y2+((h2-h)/2);
780 }
781
782
783 //Z_scripterrlog("Lines( opacity ) is: %d\n", v.at(q+9));
784 if(v.at(q+9) <= 127) //translucent
785 {
786 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
787 }
788 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
789 //Z_scripterrlog("Lines( rotation ) is: %d\n", v.at(q+8));
790 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+6));
791 //Z_scripterrlog("Lines( rot_x ) is: %d\n", v.at(q+7));
792 if( v.at(q+8) !=0 ) //rotation
793 {
794 int32_t xy[4];
795
796 int32_t rx = v.at(q+6);
797
798 int32_t ry = v.at(q+7);
799
800 fixed ra1=itofix(v.at(q+8) % 1);
801 fixed ra2=itofix(v.at(q+8));
802 fixed ra=ra1+ra2;
803
804 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
805 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
806 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
807 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
808 x1=xy[0];
809 y1=xy[1];
810 x2=xy[2];
811 y2=xy[3];
812 }
813 //Z_scripterrlog("Lines( xofs ) is: %d\n", xoffset);
814 //Z_scripterrlog("Lines( yofs ) is: %d\n", yoffset);
815 line(bmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
816 }
817 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
818 }
819
820 void do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
821 {
822 //sdci[1]=layer
823 //sdci[2]=point count
824 //sdci[3]array[]
825 //sdci[4] = colour
826 //sdci[5] = opacity
827
828 int32_t col = sdci[4]/10000;
829 int32_t op = sdci[5]/10000;
830
831 //bool brokenOffset= ( (get_er(er_BITMAPOFFSET)!=0) || (get_qr(qr_BITMAPOFFSETFIX)!=0) );
832 //Z_scripterrlog("Broken offset rule for Polygon() is: %s\n", brokenOffset ? "ON" : "OFF");
833 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
834
835 if(!v_ptr)
836 {
837 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
838 return;
839 }
840
841 std::vector<int32_t> &v = *v_ptr;
842
843 if(v.empty())
844 return;
845 //Z_scripterrlog("PutPixels reached line %d\n", 983);
846
847 int32_t* pos = &v[0];
848 int32_t sz = v.size();
849 int32_t numpoints = (sdci[2]/10000);
850 if(sz & 1) --sz; //even amount only
851 if(numpoints > sz/2) //cap to array
852 numpoints = sz/2;
853 if(numpoints < 1)
854 return; //Don't draw 0 or negative point count
855
856 //Fix the draw Y offset. -Z 20th June, 2019
857 for ( int32_t q = 1; q < sz; q+=2 )
858 {
859 pos[q] += yoffset;
860 }
861 if(op <= 127) //translucent
862 {
863 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
864 }
865 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
866
867 polygon(bmp, numpoints, (int32_t*)pos, col);
868 //polygon(bmp, (sdci[2]/10000), &v, col);
869 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
870 }
871
872 void bmp_do_polygonr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
873 {
874 //sdci[1]=layer
875 //sdci[2]=point count
876 //sdci[3]array[]
877 //sdci[4] = colour
878 //sdci[5] = opacity
879
880 int32_t col = sdci[4]/10000;
881 int32_t op = sdci[5]/10000;
882
883 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
884 {
885 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
886 return;
887 }
888 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
889 if ( refbmp == NULL ) return;
890
891 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
892
893 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
894
895 if(!v_ptr)
896 {
897 al_trace("Screen->Polygon: Vector pointer is null! Internal error. \n");
898 return;
899 }
900
901 std::vector<int32_t> &v = *v_ptr;
902
903 if(v.empty())
904 return;
905 //Z_scripterrlog("PutPixels reached line %d\n", 983);
906
907 int32_t* pos = &v[0];
908 int32_t sz = v.size();
909 int32_t numpoints = (sdci[2]/10000);
910 if(sz & 1) --sz; //even amount only
911 if(numpoints > sz/2) //cap to array
912 numpoints = sz/2;
913 if(numpoints < 1)
914 return; //Don't draw 0 or negative point count
915
916 //Fix the draw Y offset. -Z 20th June, 2019
917 for ( int32_t q = 1; q < sz; q+=2 )
918 {
919 pos[q] += yoffset;
920 }
921 if(op <= 127) //translucent
922 {
923 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
924 }
925 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
926
927 polygon(refbmp, numpoints, (int32_t*)pos, col);
928 //polygon(refbmp, (sdci[2]/10000), &v, col);
929 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
930 }
931
932 void do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
933 {
934 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
935
936 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
937 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
938 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
939 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
940 };
941
942 if(sdci[11]/10000 < 128) //translucent
943 {
944 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
945 }
946
947 spline(bmp, points, sdci[10]/10000);
948
949 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
950 }
951
952
953 404879 void do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
954 {
955 //sdci[1]=layer
956 //sdci[2]=x
957 //sdci[3]=y
958 //sdci[4]=color
959 //sdci[5]=rotation anchor x
960 //sdci[6]=rotation anchor y
961 //sdci[7]=rotation angle
962 //sdci[8]=opacity
963 404879 int32_t x1=sdci[2]/10000;
964 404879 int32_t y1=sdci[3]/10000;
965 404879 int32_t color=sdci[4]/10000;
966
967
2/2
✓ Branch 0 taken 404863 times.
✓ Branch 1 taken 16 times.
404879 if(sdci[8]/10000<=127) //translucent
968 {
969 16 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
970 16 }
971
972
1/2
✓ Branch 0 taken 404879 times.
✗ Branch 1 not taken.
404879 if(sdci[7]!=0) //rotation
973 {
974 int32_t xy[2];
975 int32_t rx=sdci[5]/10000;
976 int32_t ry=sdci[6]/10000;
977 fixed ra1=itofix(sdci[7]%10000)/10000;
978 fixed ra2=itofix(sdci[7]/10000);
979 fixed ra=ra1+ra2;
980
981 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
982 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
983 x1=xy[0];
984 y1=xy[1];
985 }
986
987 404879 putpixel(bmp, x1+xoffset, y1+yoffset, color);
988 404879 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
989 404879 }
990
991 void do_putpixelsr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
992 {
993 //Z_scripterrlog("Starting putpixels()%s\n");
994 //sdci[1]=layer
995 //sdci[2]=array {x,y,colour,opacity}
996 //sdci[3]=rotation anchor x
997 //sdci[4]=rotation anchor y
998 //sdci[5]=rotation angle
999
1000
1001 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1002
1003 if(!v_ptr)
1004 {
1005 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1006 return;
1007 }
1008
1009 std::vector<int32_t> &v = *v_ptr;
1010
1011 if(v.empty())
1012 return;
1013 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1014
1015 int32_t* pos = &v[0];
1016 int32_t sz = v.size();
1017 //Z_scripterrlog("Vector size is: %d\n", sz);
1018 //for ( int32_t m = 0; m < 256; ++m ) Z_scripterrlog("Vector contents at pos[%d]: %d\n", m, pos[m]);
1019
1020 //FFCore.getValues(sdci[2]/10000, points, sz);
1021
1022
1023 int32_t x1 = 0;
1024 int32_t y1 = 0;
1025
1026 for ( int32_t q = 0; q < sz; q+=4 )
1027 {
1028 //Z_scripterrlog("Vector q: %d\n", q);
1029 //if ( q > sz-1 ) break;
1030 x1 = v.at(q); //pos[q];
1031 y1 = v.at(q+1); //pos[q+1];
1032 //Z_scripterrlog("x1 is: %d\n", x1);
1033 //Z_scripterrlog("y1 is: %d\n", 1);
1034 if(sdci[5]!=0) //rotation
1035 {
1036 int32_t xy[2];
1037 int32_t rx=sdci[3]/10000;
1038 int32_t ry=sdci[4]/10000;
1039 fixed ra1=itofix(sdci[5]%10000)/10000;
1040 fixed ra2=itofix(sdci[5]/10000);
1041 fixed ra=ra1+ra2;
1042
1043 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1044 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1045 x1=xy[0];
1046 y1=xy[1];
1047 }
1048 //Z_scripterrlog("PutPixels()%s value is %d\n","x",x1);
1049 //Z_scripterrlog("PutPixels()%s value is %d\n","y",y1);
1050 //Z_scripterrlog("PutPixels()%s value is %d\n","colour",points[q+2]);
1051 if ( v.at(q+3) /*pos[q+3]*/ < 128 ) drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1052 else drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1053 putpixel(bmp, x1+xoffset, y1+yoffset, v.at(q+2) /*pos[q+2]*/);
1054 //if ( points[q+3] < 128 )
1055
1056 //else drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
1057 }
1058 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
1059 }
1060
1061 1536713 void do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1062 {
1063 //sdci[1]=layer
1064 //sdci[2]=x
1065 //sdci[3]=y
1066 //sdci[4]=tile
1067 //sdci[5]=tile width
1068 //sdci[6]=tile height
1069 //sdci[7]=color (cset)
1070 //sdci[8]=scale x
1071 //sdci[9]=scale y
1072 //sdci[10]=rotation anchor x
1073 //sdci[11]=rotation anchor y
1074 //sdci[12]=rotation angle
1075 //sdci[13]=flip
1076 //sdci[14]=transparency
1077 //sdci[15]=opacity
1078
1079 1536713 int32_t w = sdci[5]/10000;
1080 1536713 int32_t h = sdci[6]/10000;
1081
1082
4/8
✓ Branch 0 taken 1536713 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1536713 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1536713 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1536713 times.
1536713 if(w < 1 || h < 1 || h > 20 || w > 20)
1083 {
1084 return;
1085 }
1086
1087 1536713 int32_t xscale=sdci[8]/10000;
1088 1536713 int32_t yscale=sdci[9]/10000;
1089 1536713 int32_t rx = sdci[10]/10000;
1090 1536713 int32_t ry = sdci[11]/10000;
1091 1536713 float rotation=sdci[12]/10000;
1092 1536713 int32_t flip=(sdci[13]/10000)&3;
1093 1536713 bool transparency=sdci[14]!=0;
1094 1536713 int32_t opacity=sdci[15]/10000;
1095 1536713 int32_t color=sdci[7]/10000;
1096
1097 1536713 int32_t x1=sdci[2]/10000;
1098 1536713 int32_t y1=sdci[3]/10000;
1099
1100 //don't scale if it's not safe to do so
1101 1536713 bool canscale = true;
1102
1103
3/4
✓ Branch 0 taken 1516068 times.
✓ Branch 1 taken 20645 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1516068 times.
1536713 if(xscale==0||yscale==0)
1104 {
1105 20645 return;
1106 }
1107
1108
3/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1377103 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 138965 times.
1516068 if(xscale<=0||yscale<=0)
1109 1377103 canscale = false; //default size
1110
1111
4/4
✓ Branch 0 taken 138965 times.
✓ Branch 1 taken 1377103 times.
✓ Branch 2 taken 130807 times.
✓ Branch 3 taken 1246296 times.
1516068 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1112 {
1113 269772 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
1114
1115
1/2
✓ Branch 0 taken 269772 times.
✗ Branch 1 not taken.
269772 if(transparency) //transparency
1116 {
1117 269772 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1118 269772 }
1119 else //no transparency
1120 {
1121 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
1122 }
1123
1124
2/2
✓ Branch 0 taken 134495 times.
✓ Branch 1 taken 135277 times.
269772 if(rotation != 0)
1125 {
1126 //low negative values indicate no anchor-point rotation
1127
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 134495 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
134495 if(rx>-777||ry>-777)
1128 {
1129 int32_t xy[2];
1130 134495 fixed ra1=itofix(sdci[12]%10000)/10000;
1131 134495 fixed ra2=itofix(sdci[12]/10000);
1132 134495 fixed ra=ra1+ra2;
1133 134495 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1134 134495 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1135 134495 x1=xy[0];
1136 134495 y1=xy[1];
1137 134495 }
1138
1139
2/2
✓ Branch 0 taken 3688 times.
✓ Branch 1 taken 130807 times.
134495 if(canscale) //scale first
1140 {
1141 //damnit all, .. fixme.
1142
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3688 times.
3688 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1143 3688 clear_bitmap(tempbit);
1144
1145 3688 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1146
1147
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3688 times.
3688 if(opacity < 128)
1148 {
1149 clear_bitmap(prim_bmp);
1150 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1151 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1152 }
1153 else
1154 {
1155 3688 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1156 }
1157
1158 3688 destroy_bitmap(tempbit);
1159 3688 }
1160 else //no scale
1161 {
1162
2/2
✓ Branch 0 taken 3586 times.
✓ Branch 1 taken 127221 times.
130807 if(opacity < 128)
1163 {
1164 3586 clear_bitmap(prim_bmp);
1165 3586 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1166 3586 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1167 3586 }
1168 else
1169 {
1170 127221 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1171 }
1172 }
1173 134495 }
1174 else //scale only
1175 {
1176
1/2
✓ Branch 0 taken 135277 times.
✗ Branch 1 not taken.
135277 if(canscale)
1177 {
1178
2/2
✓ Branch 0 taken 2832 times.
✓ Branch 1 taken 132445 times.
135277 if(opacity<128)
1179 {
1180 2832 clear_bitmap(prim_bmp);
1181 2832 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1182 2832 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1183 2832 }
1184 else
1185 {
1186 132445 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1187 }
1188 135277 }
1189 else //error -do not scale
1190 {
1191 if(opacity<128)
1192 {
1193 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1194 }
1195 else
1196 {
1197 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1198 }
1199 }
1200 }
1201
1202 269772 script_drawing_commands.ReleaseSubBitmap(pbitty);
1203
1204 269772 }
1205 else // no scale or rotation
1206 {
1207
2/2
✓ Branch 0 taken 1218842 times.
✓ Branch 1 taken 27454 times.
1246296 if(transparency)
1208 {
1209
2/2
✓ Branch 0 taken 224692 times.
✓ Branch 1 taken 994150 times.
1218842 if(opacity<=127)
1210 224692 TileHelper::OverTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1211 else
1212 994150 TileHelper::OverTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1213 1218842 }
1214 else
1215 {
1216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 27454 times.
27454 if(opacity<=127)
1217 TileHelper::PutTileTranslucent(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
1218 else
1219 27454 TileHelper::OldPutTile(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
1220 }
1221 }
1222 1536713 }
1223
1224 void do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1225 {
1226 //sdci[1]=layer
1227 //sdci[2]=x
1228 //sdci[3]=y
1229 //sdci[4]=tile
1230 //sdci[5]=tile width
1231 //sdci[6]=tile height
1232 //sdci[7]=flip
1233
1234 int32_t w = sdci[5]/10000;
1235 int32_t h = sdci[6]/10000;
1236
1237 if(w < 1 || h < 1 || h > 20 || w > 20)
1238 {
1239 return;
1240 }
1241
1242 int32_t flip=(sdci[7]/10000)&3;
1243
1244 int32_t x1=sdci[2]/10000;
1245 int32_t y1=sdci[3]/10000;
1246
1247 TileHelper::OverTileCloaked(bmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
1248 }
1249
1250
1251 2543992 void do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1252 {
1253 //sdci[1]=layer
1254 //sdci[2]=x
1255 //sdci[3]=y
1256 //sdci[4]=combo
1257 //sdci[5]=tile width
1258 //sdci[6]=tile height
1259 //sdci[7]=color (cset)
1260 //sdci[8]=scale x
1261 //sdci[9]=scale y
1262 //sdci[10]=rotation anchor x
1263 //sdci[11]=rotation anchor y
1264 //sdci[12]=rotation angle
1265 //sdci[13]=frame
1266 //sdci[14]=flip
1267 //sdci[15]=transparency
1268 //sdci[16]=opacity
1269
1270 2543992 int32_t w = sdci[5]/10000;
1271 2543992 int32_t h = sdci[6]/10000;
1272
1273
4/8
✓ Branch 0 taken 2543992 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2543992 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2543992 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 2543992 times.
2543992 if(w<1||h<1||h>20||w>20)
1274 {
1275 return;
1276 }
1277 2543992 int32_t cmb = (sdci[4]/10000);
1278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2543992 times.
2543992 if((unsigned)cmb >= MAXCOMBOS)
1279 {
1280 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1281 return;
1282 }
1283
1284 2543992 int32_t xscale=sdci[8]/10000;
1285 2543992 int32_t yscale=sdci[9]/10000;
1286 2543992 int32_t rx = sdci[10]/10000; //these work now
1287 2543992 int32_t ry = sdci[11]/10000; //these work now
1288 2543992 float rotation=sdci[12]/10000;
1289
1290 2543992 bool transparency=sdci[15]!=0;
1291 2543992 int32_t opacity=sdci[16]/10000;
1292 2543992 int32_t color=sdci[7]/10000;
1293 2543992 int32_t x1=sdci[2]/10000;
1294 2543992 int32_t y1=sdci[3]/10000;
1295
1296 2543992 const newcombo & c = combobuf[cmb];
1297 2543992 int32_t tiletodraw = combo_tile(c, x1, y1);
1298 2543992 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
1299 2543992 int32_t skiprows=c.skipanimy;
1300
1301
1302 //don't scale if it's not safe to do so
1303 2543992 bool canscale = true;
1304
1305
3/4
✓ Branch 0 taken 2543941 times.
✓ Branch 1 taken 51 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2543941 times.
2543992 if(xscale==0||yscale==0)
1306 {
1307 51 return;
1308 }
1309
1310
3/4
✓ Branch 0 taken 22484 times.
✓ Branch 1 taken 2521457 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 22484 times.
2543941 if(xscale<=0||yscale<=0)
1311 2521457 canscale = false; //default size
1312
1313
4/4
✓ Branch 0 taken 22484 times.
✓ Branch 1 taken 2521457 times.
✓ Branch 2 taken 98637 times.
✓ Branch 3 taken 2422820 times.
2543941 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
1314 {
1315 121121 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
1316
1317
2/2
✓ Branch 0 taken 120085 times.
✓ Branch 1 taken 1036 times.
121121 if(transparency)
1318 {
1319 120085 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1320 120085 }
1321 else //no transparency
1322 {
1323 1036 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
1324 }
1325
1326
2/2
✓ Branch 0 taken 98746 times.
✓ Branch 1 taken 22375 times.
121121 if(rotation != 0) // rotate
1327 {
1328 //fixed point sucks ;0
1329
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 98746 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
98746 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
1330 {
1331 int32_t xy[2];
1332 98746 fixed ra1=itofix(sdci[12]%10000)/10000;
1333 98746 fixed ra2=itofix(sdci[12]/10000);
1334 98746 fixed ra=ra1+ra2;
1335 98746 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
1336 98746 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
1337 98746 x1=xy[0];
1338 98746 y1=xy[1];
1339 98746 }
1340
1341
2/2
✓ Branch 0 taken 109 times.
✓ Branch 1 taken 98637 times.
98746 if(canscale) //scale first
1342 {
1343
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 109 times.
109 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
1344 109 clear_bitmap(tempbit);
1345
1346 109 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
1347
1348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 109 times.
109 if(opacity < 128)
1349 {
1350 clear_bitmap(prim_bmp);
1351 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
1352 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1353 }
1354 else
1355 {
1356 109 rotate_sprite(bmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1357 }
1358
1359 109 destroy_bitmap(tempbit);
1360 109 }
1361 else //no scale
1362 {
1363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 98637 times.
98637 if(opacity < 128)
1364 {
1365 clear_bitmap(prim_bmp);
1366 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
1367 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1368 }
1369 else
1370 {
1371 98637 rotate_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
1372 }
1373 }
1374 98746 }
1375 else //scale only
1376 {
1377
1/2
✓ Branch 0 taken 22375 times.
✗ Branch 1 not taken.
22375 if(canscale)
1378 {
1379
2/2
✓ Branch 0 taken 9333 times.
✓ Branch 1 taken 13042 times.
22375 if(opacity<128)
1380 {
1381 9333 clear_bitmap(prim_bmp);
1382 9333 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
1383 9333 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1384 9333 }
1385 else
1386 {
1387 13042 stretch_sprite(bmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
1388 }
1389 22375 }
1390 else //error -do not scale
1391 {
1392 if(opacity<128)
1393 {
1394 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
1395 }
1396 else
1397 {
1398 draw_sprite(bmp, pbitty, x1+xoffset, y1+yoffset);
1399 }
1400 }
1401 }
1402
1403 121121 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
1404 121121 }
1405 else // no scale or rotation
1406 {
1407
1/2
✓ Branch 0 taken 2422820 times.
✗ Branch 1 not taken.
2422820 if(transparency)
1408 {
1409
2/2
✓ Branch 0 taken 60880 times.
✓ Branch 1 taken 2361940 times.
2422820 if(opacity<=127)
1410 60880 TileHelper::OverTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1411 else
1412 2361940 TileHelper::OverTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1413 2422820 }
1414 else
1415 {
1416 if(opacity<=127)
1417 TileHelper::PutTileTranslucent(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
1418 else
1419 TileHelper::OldPutTile(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
1420 }
1421 }
1422 2543992 }
1423
1424 void do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1425 {
1426 //sdci[1]=layer
1427 //sdci[2]=x
1428 //sdci[3]=y
1429 //sdci[4]=combo
1430 //sdci[5]=tile width
1431 //sdci[6]=tile height
1432 //sdci[7]=flip
1433
1434 int32_t w = sdci[5]/10000;
1435 int32_t h = sdci[6]/10000;
1436
1437 if(w<1||h<1||h>20||w>20)
1438 {
1439 return;
1440 }
1441 int32_t cmb = (sdci[4]/10000);
1442 if((unsigned)cmb >= MAXCOMBOS)
1443 {
1444 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1445 return;
1446 }
1447
1448 int32_t x1=sdci[2]/10000;
1449 int32_t y1=sdci[3]/10000;
1450
1451 const newcombo & c = combobuf[cmb];
1452 int32_t tiletodraw = combo_tile(c, x1, y1);
1453 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
1454 int32_t skiprows=c.skipanimy;
1455
1456 TileHelper::OverTileCloaked(bmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
1457 }
1458
1459
1460 5287220 void do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1461 {
1462 /* layer, x, y, tile, color opacity */
1463
1464 5287220 int32_t opacity = sdci[6]/10000;
1465
1466
2/2
✓ Branch 0 taken 153668 times.
✓ Branch 1 taken 5133552 times.
5287220 if(opacity < 128)
1467 153668 overtiletranslucent16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
1468 else
1469 5133552 overtile16(bmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
1470 5287220 }
1471
1472 void do_fasttilesr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1473 {
1474 /* layer, x, y, tile, color opacity */
1475
1476 //sdci[1]=layer
1477 //sdci[2]=array {x,y,tile,colour,opacity}
1478
1479 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1480
1481 if(!v_ptr)
1482 {
1483 al_trace("Screen->PutPixels: Vector pointer is null! Internal error. \n");
1484 return;
1485 }
1486
1487 std::vector<int32_t> &v = *v_ptr;
1488
1489 if(v.empty())
1490 return;
1491 //Z_scripterrlog("PutPixels reached line %d\n", 983);
1492
1493 int32_t* pos = &v[0];
1494 int32_t sz = v.size();
1495
1496 for ( int32_t q = 0; q < sz; q+=5 )
1497 {
1498
1499 if(v.at(q+4) < 128)
1500 overtiletranslucent16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0, v.at(q+4));
1501 else
1502 overtile16(bmp, v.at(q+2), xoffset+(v.at(q)), yoffset+(v.at(q+1)), v.at(q+3), 0);
1503 }
1504 }
1505
1506
1507
1508 21409189 void do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1509 {
1510 /* layer, x, y, tile, color opacity */
1511
1512 21409189 int32_t opacity = sdci[6] / 10000;
1513 21409189 int32_t x1 = sdci[2] / 10000;
1514 21409189 int32_t y1 = sdci[3] / 10000;
1515
1516 21409189 int32_t cmb = (sdci[4]/10000);
1517
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21409189 times.
21409189 if((unsigned)cmb >= MAXCOMBOS)
1518 {
1519 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
1520 return;
1521 }
1522
1523
2/2
✓ Branch 0 taken 177396 times.
✓ Branch 1 taken 21231793 times.
21409189 if(opacity < 128)
1524 {
1525 177396 overcomboblocktranslucent(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
1526
1527 177396 }
1528 else
1529 {
1530 21231793 overcomboblock(bmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
1531 }
1532 21409189 }
1533
1534 void do_fastcombosr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1535 {
1536 /* layer, x, y, combo, cset, opacity */
1537 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
1538
1539 if(!v_ptr)
1540 {
1541 al_trace("Screen->FastCombos: Vector pointer is null! Internal error. \n");
1542 return;
1543 }
1544
1545 std::vector<int32_t> &v = *v_ptr;
1546
1547 if(v.empty())
1548 return;
1549
1550 int32_t* pos = &v[0];
1551 int32_t sz = v.size();
1552
1553 for ( int32_t q = 0; q < sz; q+=5 )
1554 {
1555 if((unsigned)(v.at(q+2)) >= MAXCOMBOS)
1556 {
1557 Z_scripterrlog("FastCombos() cannot draw combo '%d', as it is out of bounds.\n", v.at(q+2));
1558 continue;
1559 }
1560 if(v.at(q+4) < 128)
1561 {
1562 overcomboblocktranslucent(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1, 128);
1563
1564 }
1565 else
1566 {
1567 overcomboblock(bmp, xoffset+v.at(q), yoffset+v.at(q+1), v.at(q+2), v.at(q+3), 1, 1);
1568 }
1569 }
1570 }
1571
1572
1573
1574
1575 962949 void do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1576 {
1577 //broken 2.50.2 and earlier drawcharacter()
1578
2/2
✓ Branch 0 taken 17778 times.
✓ Branch 1 taken 945171 times.
962949 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1579 {
1580 //sdci[1]=layer
1581 //sdci[2]=x
1582 //sdci[3]=y
1583 //sdci[4]=font
1584 //sdci[5]=color
1585 //sdci[6]=bg color
1586 //sdci[7]=strech x (width)
1587 //sdci[8]=stretch y (height)
1588 //sdci[9]=char
1589 //sdci[10]=opacity
1590
1591 17778 int32_t x=sdci[2]/10000;
1592 17778 int32_t y=sdci[3]/10000;
1593 17778 int32_t font_index=sdci[4]/10000;
1594 17778 int32_t color=sdci[5]/10000;
1595 17778 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1596 17778 int32_t w=sdci[7]/10000;
1597 17778 int32_t h=sdci[8]/10000;
1598 17778 char glyph=char(sdci[9]/10000);
1599 17778 int32_t opacity=sdci[10]/10000;
1600
1601 //safe check
1602
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(bg_color < -1) bg_color = -1;
1603
1604
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(w>512) w=512; //w=vbound(w,0,512);
1605
1606
1/2
✓ Branch 0 taken 17778 times.
✗ Branch 1 not taken.
17778 if(h>512) h=512; //h=vbound(h,0,512);
1607
1608 //undone
1609
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
17778 if(w>0&&h>0)//stretch the character
1610 {
1611 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1612
1613 if(opacity < 128)
1614 {
1615 if(w>128||h>128)
1616 {
1617 clear_bitmap(prim_bmp);
1618
1619 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1620 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1621 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1622 }
1623 else //this is faster
1624 {
1625 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1626
1627 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1628 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1629 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1630
1631 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1632 }
1633 }
1634 else // no opacity
1635 {
1636 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1637 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1638 }
1639
1640 }
1641 else //no stretch
1642 {
1643
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17778 times.
17778 if(opacity < 128)
1644 {
1645 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1646 clear_bitmap(pbmp);
1647
1648 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1649 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1650
1651 destroy_bitmap(pbmp);
1652 }
1653 else // no opacity
1654 {
1655 17778 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1656 }
1657 }
1658 17778 }
1659
1660 else //2.53.0 fixed version and later.
1661 {
1662
1663 //sdci[1]=layer
1664 //sdci[2]=x
1665 //sdci[3]=y
1666 //sdci[4]=font
1667 //sdci[5]=color
1668 //sdci[6]=bg color
1669 //sdci[7]=strech x (width)
1670 //sdci[8]=stretch y (height)
1671 //sdci[9]=char
1672 //sdci[10]=opacity
1673
1674 945171 int32_t x=sdci[2]/10000;
1675 945171 int32_t y=sdci[3]/10000;
1676 945171 int32_t font_index=sdci[4]/10000;
1677 945171 int32_t color=sdci[5]/10000;
1678 945171 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1679 945171 int32_t w=sdci[7]/10000;
1680 945171 int32_t h=sdci[8]/10000;
1681 945171 char glyph=char(sdci[9]/10000);
1682 945171 int32_t opacity=sdci[10]/10000;
1683
1684 //safe check
1685
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(bg_color < -1) bg_color = -1;
1686
1687
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(w>512) w=512; //w=vbound(w,0,512);
1688
1689
1/2
✓ Branch 0 taken 945171 times.
✗ Branch 1 not taken.
945171 if(h>512) h=512; //h=vbound(h,0,512);
1690
1691 //undone
1692
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
945171 if(w>0&&h>0)//stretch the character
1693 {
1694 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1695
1696 if(opacity < 128)
1697 {
1698 if(w>128||h>128)
1699 {
1700 clear_bitmap(prim_bmp);
1701
1702 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1703 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1704 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1705 }
1706 else //this is faster
1707 {
1708 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
1709
1710 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1711 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1712 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1713
1714 script_drawing_commands.ReleaseSubBitmap(pbmp2);
1715 }
1716 }
1717 else // no opacity
1718 {
1719 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1720 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1721 }
1722
1723 }
1724 else //no stretch
1725 {
1726
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 945171 times.
945171 if(opacity < 128)
1727 {
1728 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1729 clear_bitmap(pbmp);
1730
1731 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
1732 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1733
1734 destroy_bitmap(pbmp);
1735 }
1736 else // no opacity
1737 {
1738 945171 textprintf_ex(bmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
1739 }
1740 }
1741
1742 }
1743
1744 962949 }
1745
1746
1747 138747 void do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1748 {
1749 //broken 2.50.2 and earlier drawinteger()
1750
2/2
✓ Branch 0 taken 72533 times.
✓ Branch 1 taken 66214 times.
138747 if ( get_qr(qr_BROKENCHARINTDRAWING) )
1751 {
1752 //sdci[1]=layer
1753 //sdci[2]=x
1754 //sdci[3]=y
1755 //sdci[4]=font
1756 //sdci[5]=color
1757 //sdci[6]=bg color
1758 //sdci[7]=strech x (width)
1759 //sdci[8]=stretch y (height)
1760 //sdci[9]=integer
1761 //sdci[10]=num decimal places
1762 //sdci[11]=opacity
1763
1764 72533 int32_t x=sdci[2]/10000;
1765 72533 int32_t y=sdci[3]/10000;
1766 72533 int32_t font_index=sdci[4]/10000;
1767 72533 int32_t color=sdci[5]/10000;
1768 72533 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1769 72533 int32_t w=sdci[7]/10000;
1770 72533 int32_t h=sdci[8]/10000;
1771 72533 int32_t decplace=sdci[10]/10000;
1772 72533 int32_t opacity=sdci[11]/10000;
1773
1774 //safe check
1775
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(bg_color < -1) bg_color = -1;
1776
1777
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(w>512) w=512; //w=vbound(w,0,512);
1778
1779
1/2
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
72533 if(h>512) h=512; //h=vbound(h,0,512);
1780
1781 char numbuf[15];
1782
1783
1/6
✓ Branch 0 taken 72533 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
72533 switch(decplace)
1784 {
1785 default:
1786 case 0:
1787 72533 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1788 72533 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1789
1790 case 1:
1791 //sprintf(numbuf,"%.01f",number);
1792 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1793 break;
1794
1795 case 2:
1796 //sprintf(numbuf,"%.02f",number);
1797 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1798 break;
1799
1800 case 3:
1801 //sprintf(numbuf,"%.03f",number);
1802 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1803 break;
1804
1805 case 4:
1806 //sprintf(numbuf,"%.04f",number);
1807 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1808 break;
1809 }
1810
1811
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
72533 if(w>0&&h>0)//stretch
1812 {
1813 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
1814
1815 if(opacity < 128)
1816 {
1817 if(w>128||h>128)
1818 {
1819 clear_bitmap(prim_bmp);
1820
1821 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1822 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1823 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1824 }
1825 else
1826 {
1827 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1828 clear_bitmap(pbmp2);
1829
1830 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1831 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1832 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1833
1834 destroy_bitmap(pbmp2);
1835 }
1836 }
1837 else // no opacity
1838 {
1839 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1840 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1841 }
1842
1843 }
1844 else //no stretch
1845 {
1846
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72533 times.
72533 if(opacity < 128)
1847 {
1848 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
1849 clear_bitmap(pbmp);
1850
1851 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1852 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1853
1854 destroy_bitmap(pbmp);
1855 }
1856 else // no opacity
1857 {
1858 72533 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1859 }
1860 }
1861
1862 72533 }
1863
1864 else //2.53.0 fixed version and later.
1865 {
1866 //sdci[1]=layer
1867 //sdci[2]=x
1868 //sdci[3]=y
1869 //sdci[4]=font
1870 //sdci[5]=color
1871 //sdci[6]=bg color
1872 //sdci[7]=strech x (width)
1873 //sdci[8]=stretch y (height)
1874 //sdci[9]=integer
1875 //sdci[10]=num decimal places
1876 //sdci[11]=opacity
1877
1878 66214 int32_t x=sdci[2]/10000;
1879 66214 int32_t y=sdci[3]/10000;
1880 66214 int32_t font_index=sdci[4]/10000;
1881 66214 int32_t color=sdci[5]/10000;
1882 66214 int32_t bg_color=sdci[6]/10000; //-1 = transparent
1883 66214 int32_t w=sdci[7]/10000;
1884 66214 int32_t h=sdci[8]/10000;
1885 66214 int32_t decplace=sdci[10]/10000;
1886 66214 int32_t opacity=sdci[11]/10000;
1887
1888 //safe check
1889
1/2
✓ Branch 0 taken 66214 times.
✗ Branch 1 not taken.
66214 if(bg_color < -1) bg_color = -1;
1890
1891
1/2
✓ Branch 0 taken 66214 times.
✗ Branch 1 not taken.
66214 if(w>512) w=512; //w=vbound(w,0,512);
1892
1893
1/2
✓ Branch 0 taken 66214 times.
✗ Branch 1 not taken.
66214 if(h>512) h=512; //h=vbound(h,0,512);
1894
1895 char numbuf[15];
1896
1897
1/6
✓ Branch 0 taken 66214 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
66214 switch(decplace)
1898 {
1899 default:
1900 case 0:
1901 66214 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
1902 66214 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
1903
1904 case 1:
1905 //sprintf(numbuf,"%.01f",number);
1906 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
1907 break;
1908
1909 case 2:
1910 //sprintf(numbuf,"%.02f",number);
1911 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
1912 break;
1913
1914 case 3:
1915 //sprintf(numbuf,"%.03f",number);
1916 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
1917 break;
1918
1919 case 4:
1920 //sprintf(numbuf,"%.04f",number);
1921 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
1922 break;
1923 }
1924
1925 //FONT* font=get_zc_font(sdci[4]/10000);
1926
1927
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 66214 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
66214 if(w>0&&h>0)//stretch
1928 {
1929 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
1930 clear_bitmap(pbmp);
1931 //script_drawing_commands.GetSmallTextureBitmap(1,1);
1932
1933 if(opacity < 128)
1934 {
1935 if(w>128||h>128)
1936 {
1937 clear_bitmap(prim_bmp);
1938
1939 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1940 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
1941 draw_trans_sprite(bmp, prim_bmp, x+xoffset, y+yoffset);
1942 }
1943 else
1944 {
1945 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
1946 clear_bitmap(pbmp2);
1947
1948 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1949 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
1950 draw_trans_sprite(bmp, pbmp2, x+xoffset, y+yoffset);
1951
1952 destroy_bitmap(pbmp2);
1953 }
1954 }
1955 else // no opacity
1956 {
1957 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
1958 stretch_sprite(bmp, pbmp, x+xoffset, y+yoffset, w, h);
1959 }
1960
1961 }
1962 else //no stretch
1963 {
1964
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66214 times.
66214 if(opacity < 128)
1965 {
1966 FONT* font = get_zc_font(font_index);
1967 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
1968 clear_bitmap(pbmp);
1969
1970 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
1971 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
1972
1973 destroy_bitmap(pbmp);
1974 }
1975 else // no opacity
1976 {
1977 66214 textout_ex(bmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
1978 }
1979 }
1980 }
1981 138747 }
1982
1983
1984 1558269 void do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
1985 {
1986 //sdci[1]=layer
1987 //sdci[2]=x
1988 //sdci[3]=y
1989 //sdci[4]=font
1990 //sdci[5]=color
1991 //sdci[6]=bg color
1992 //sdci[7]=format_option
1993 //sdci[8]=string
1994 //sdci[9]=opacity
1995
1996 1558269 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
1997
1998
1/2
✓ Branch 0 taken 1558269 times.
✗ Branch 1 not taken.
1558269 if(!str)
1999 {
2000 al_trace("String pointer is null! Internal error. \n");
2001 return;
2002 }
2003
2004 1558269 int32_t x=sdci[2]/10000;
2005 1558269 int32_t y=sdci[3]/10000;
2006 1558269 FONT* font=get_zc_font(sdci[4]/10000);
2007 1558269 int32_t color=sdci[5]/10000;
2008 1558269 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2009 1558269 int32_t format_type=sdci[7]/10000;
2010 1558269 int32_t opacity=sdci[9]/10000;
2011 //sdci[8] not needed :)
2012
2013 //safe check
2014
1/2
✓ Branch 0 taken 1558269 times.
✗ Branch 1 not taken.
1558269 if(bg_color < -1) bg_color = -1;
2015
2016
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1558269 times.
1558269 if(opacity < 128)
2017 {
2018 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2019 if (width < 1) return; //SANITY -Em
2020 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2021 clear_bitmap(pbmp);
2022 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2023 if(format_type == 2) // right-sided text
2024 x-=width;
2025 else if(format_type == 1) // centered text
2026 x-=width/2;
2027 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2028 destroy_bitmap(pbmp);
2029 }
2030 else // no opacity
2031 {
2032
2/2
✓ Branch 0 taken 14345 times.
✓ Branch 1 taken 1543924 times.
1558269 if(format_type == 2) // right-sided text
2033 {
2034 14345 textout_right_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2035 14345 }
2036
2/2
✓ Branch 0 taken 723406 times.
✓ Branch 1 taken 820518 times.
1543924 else if(format_type == 1) // centered text
2037 {
2038 723406 textout_centre_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2039 723406 }
2040 else // standard left-sided text
2041 {
2042 820518 textout_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
2043 }
2044 }
2045 1558269 }
2046
2047 163717 void do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2048 {
2049 //sdci[1]=layer
2050 //sdci[2]=x
2051 //sdci[3]=y
2052 //sdci[4]=font
2053 //sdci[5]=color
2054 //sdci[6]=bg color
2055 //sdci[7]=format_option
2056 //sdci[8]=string
2057 //sdci[9]=opacity
2058 //sdci[10]=shadowtype
2059 //sdci[11]=shadow_color
2060
2061 163717 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
2062
2063
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(!str)
2064 {
2065 al_trace("String pointer is null! Internal error. \n");
2066 return;
2067 }
2068
2069 163717 int32_t x=sdci[2]/10000;
2070 163717 int32_t y=sdci[3]/10000;
2071 163717 FONT* font=get_zc_font(sdci[4]/10000);
2072 163717 int32_t color=sdci[5]/10000;
2073 163717 int32_t bg_color=sdci[6]/10000; //-1 = transparent
2074 163717 int32_t format_type=sdci[7]/10000;
2075 163717 int32_t opacity=sdci[9]/10000;
2076 163717 int32_t textstyle = sdci[10]/10000;
2077 163717 int32_t shadow_color = sdci[11]/10000;
2078 //sdci[8] not needed :)
2079
2080 //safe check
2081
1/2
✓ Branch 0 taken 163717 times.
✗ Branch 1 not taken.
163717 if(bg_color < -1) bg_color = -1;
2082
2083
2/2
✓ Branch 0 taken 740 times.
✓ Branch 1 taken 162977 times.
163717 if(opacity < 128)
2084 {
2085
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 int32_t width=zc_min(text_length(font, str->c_str()), 512);
2086
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 if (width < 1) return; //SANITY -Em
2087 740 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
2088 740 clear_bitmap(pbmp);
2089 740 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
2090 740 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
2091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 740 times.
740 if(format_type == 2) // right-sided text
2092 x-=width;
2093
1/2
✓ Branch 0 taken 740 times.
✗ Branch 1 not taken.
740 else if(format_type == 1) // centered text
2094 740 x-=width/2;
2095 740 draw_trans_sprite(bmp, pbmp, x+xoffset, y+yoffset);
2096 740 destroy_bitmap(pbmp);
2097 740 }
2098 else // no opacity
2099 {
2100 162977 textout_styled_aligned_ex(bmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
2101 }
2102 163717 }
2103
2104
2105 9266 void do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2106 {
2107 //sdci[1]=layer
2108 //sdci[2]=x1
2109 //sdci[3]=y1
2110 //sdci[4]=x2
2111 //sdci[5]=y2
2112 //sdci[6]=x3
2113 //sdci[7]=y3
2114 //sdci[8]=x4
2115 //sdci[9]=y4
2116 //sdci[10]=width
2117 //sdci[11]=height
2118 //sdci[12]=cset
2119 //sdci[13]=flip
2120 //sdci[14]=tile/combo
2121 //sdci[15]=polytype
2122
2123 9266 int32_t x1 = sdci[2]/10000;
2124 9266 int32_t y1 = sdci[3]/10000;
2125 9266 int32_t x2 = sdci[4]/10000;
2126 9266 int32_t y2 = sdci[5]/10000;
2127 9266 int32_t x3 = sdci[6]/10000;
2128 9266 int32_t y3 = sdci[7]/10000;
2129 9266 int32_t x4 = sdci[8]/10000;
2130 9266 int32_t y4 = sdci[9]/10000;
2131 9266 int32_t w = sdci[10]/10000;
2132 9266 int32_t h = sdci[11]/10000;
2133 9266 int32_t color = sdci[12]/10000;
2134 9266 int32_t flip=(sdci[13]/10000)&3;
2135 9266 int32_t tile = sdci[14]/10000;
2136 9266 int32_t polytype = sdci[15]/10000;
2137
2138 //todo: finish palette shading
2139 /*
2140 POLYTYPE_FLAT
2141 POLYTYPE_GCOL
2142 POLYTYPE_GRGB
2143 POLYTYPE_ATEX
2144 POLYTYPE_PTEX
2145 POLYTYPE_ATEX_MASK
2146 POLYTYPE_PTEX_MASK
2147 POLYTYPE_ATEX_LIT
2148 POLYTYPE_PTEX_LIT
2149 POLYTYPE_ATEX_MASK_LIT
2150 POLYTYPE_PTEX_MASK_LIT
2151 POLYTYPE_ATEX_TRANS
2152 POLYTYPE_PTEX_TRANS
2153 POLYTYPE_ATEX_MASK_TRANS
2154 POLYTYPE_PTEX_MASK_TRANS
2155 */
2156 9266 polytype = vbound(polytype, 0, 14);
2157
2158
2/4
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9266 times.
9266 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2159 {
2160 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2161 return; //non power of two error
2162 }
2163
2164 9266 int32_t tex_width = w*16;
2165 9266 int32_t tex_height = h*16;
2166
2167 BITMAP *tex;
2168
2169 9266 bool mustDestroyBmp = false;
2170
2171
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile > 65519 ) tex = zscriptDrawingRenderTarget->GetBitmapPtr(tile - 65519);
2172 9266 else tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2173
2174
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(!tex)
2175 {
2176 mustDestroyBmp = true;
2177 tex = create_bitmap_ex(8, tex_width, tex_height);
2178 clear_bitmap(tex);
2179 }
2180
2181 int32_t col[4];
2182 /*
2183 if( color < 0 )
2184 {
2185 col[0]=draw_container.color_buffer[0];
2186 col[1]=draw_container.color_buffer[1];
2187 col[2]=draw_container.color_buffer[2];
2188 col[3]=draw_container.color_buffer[3];
2189 }
2190 else */
2191 {
2192 9266 col[0]=col[1]=col[2]=col[3]=color;
2193 }
2194
2195
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9266 if(tile > 0 && tile <= 65519) // TILE
2196 {
2197 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2198 }
2199
2200
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if ( tile < 0 ) // COMBO
2201 {
2202 9266 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2203 9266 const int32_t tiletodraw = combo_tile(c, x1, y1);
2204 9266 flip = flip ^ c.flip;
2205
2206 9266 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2207 9266 }
2208
2209 9266 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2210 9266 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2211 9266 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2212 9266 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(tex_width), 0, col[3] };
2213
2214 9266 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
2215
2216
1/2
✓ Branch 0 taken 9266 times.
✗ Branch 1 not taken.
9266 if(mustDestroyBmp)
2217 destroy_bitmap(tex);
2218
2219 9266 }
2220
2221
2222 void do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2223 {
2224 //sdci[1]=layer
2225 //sdci[2]=x1
2226 //sdci[3]=y1
2227 //sdci[4]=x2
2228 //sdci[5]=y2
2229 //sdci[6]=x3
2230 //sdci[7]=y3
2231 //sdci[8]=width
2232 //sdci[9]=height
2233 //sdci[10]=cset
2234 //sdci[11]=flip
2235 //sdci[12]=tile/combo
2236 //sdci[13]=polytype
2237
2238 int32_t x1 = sdci[2]/10000;
2239 int32_t y1 = sdci[3]/10000;
2240 int32_t x2 = sdci[4]/10000;
2241 int32_t y2 = sdci[5]/10000;
2242 int32_t x3 = sdci[6]/10000;
2243 int32_t y3 = sdci[7]/10000;
2244 int32_t w = sdci[8]/10000;
2245 int32_t h = sdci[9]/10000;
2246 int32_t color = sdci[10]/10000;
2247 int32_t flip=(sdci[11]/10000)&3;
2248 int32_t tile = sdci[12]/10000;
2249 int32_t polytype = sdci[13]/10000;
2250
2251 polytype = vbound(polytype, 0, 14);
2252
2253 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
2254 {
2255 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
2256 return; //non power of two error
2257 }
2258
2259 int32_t tex_width = w*16;
2260 int32_t tex_height = h*16;
2261
2262 bool mustDestroyBmp = false;
2263 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
2264
2265 if(!tex)
2266 {
2267 mustDestroyBmp = true;
2268 tex = create_bitmap_ex(8, tex_width, tex_height);
2269 clear_bitmap(tex);
2270 }
2271
2272 int32_t col[3];
2273 /*
2274 if( color < 0 )
2275 {
2276 col[0]=draw_container.color_buffer[0];
2277 col[1]=draw_container.color_buffer[1];
2278 col[2]=draw_container.color_buffer[2];
2279 }
2280 else */
2281 {
2282 col[0]=col[1]=col[2]=color;
2283 }
2284
2285 if(tile > 0) // TILE
2286 {
2287 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
2288 }
2289 else // COMBO
2290 {
2291 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
2292 const int32_t tiletodraw = combo_tile(c, x1, y1);
2293 flip = flip ^ c.flip;
2294
2295 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
2296 }
2297
2298 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
2299 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
2300 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
2301
2302
2303 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
2304
2305 if(mustDestroyBmp)
2306 destroy_bitmap(tex);
2307 }
2308
2309
2310 928052 void do_drawbitmapr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2311 {
2312 //sdci[1]=layer
2313 //sdci[2]=bitmap
2314 //sdci[3]=sourcex
2315 //sdci[4]=sourcey
2316 //sdci[5]=sourcew
2317 //sdci[6]=sourceh
2318 //sdci[7]=destx
2319 //sdci[8]=desty
2320 //sdci[9]=destw
2321 //sdci[10]=desth
2322 //sdci[11]=rotation
2323 //sdci[12]=mask
2324
2325 928052 int32_t bitmapIndex = sdci[2]/10000;
2326 928052 int32_t sx = sdci[3]/10000;
2327 928052 int32_t sy = sdci[4]/10000;
2328 928052 int32_t sw = sdci[5]/10000;
2329 928052 int32_t sh = sdci[6]/10000;
2330 928052 int32_t dx = sdci[7]/10000;
2331 928052 int32_t dy = sdci[8]/10000;
2332 928052 int32_t dw = sdci[9]/10000;
2333 928052 int32_t dh = sdci[10]/10000;
2334 928052 float rot = sdci[11]/10000;
2335 928052 bool masked = (sdci[12] != 0);
2336
2337 //bugfix
2338 928052 sx = vbound(sx, 0, 512);
2339 928052 sy = vbound(sy, 0, 512);
2340 928052 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2341 928052 sh = vbound(sh, 0, 512 - sy);
2342
2343
2344
2/4
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 928052 times.
928052 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2345 return;
2346
2347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 928052 times.
928052 bool stretched = (sw != dw || sh != dh);
2348
2349 928052 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2350
2351
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(!sourceBitmap)
2352 {
2353 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2354 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2355 return;
2356 }
2357
2358 928052 BITMAP* subBmp = 0;
2359
2360
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(rot != 0)
2361 {
2362 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2363
2364 if(!subBmp)
2365 {
2366 Z_scripterrlog("DrawBitmap() failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2367 return;
2368 }
2369 }
2370
2371
2372 928052 dx = dx + xoffset;
2373 928052 dy = dy + yoffset;
2374
2375
2/2
✓ Branch 0 taken 240 times.
✓ Branch 1 taken 927812 times.
928052 if(stretched)
2376 {
2377
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(masked)
2378 {
2379
1/2
✓ Branch 0 taken 240 times.
✗ Branch 1 not taken.
240 if(rot != 0)
2380 {
2381 //if ( rot == 4096 ) { //translucent
2382 // masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2383 // //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2384 // draw_trans_sprite(bmp, subBmp, dx, dy);
2385 // //draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, 0);
2386
2387
2388 // }
2389 //else {
2390 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2391 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2392 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2393 //
2394
2395 // }
2396 }
2397 else
2398 240 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2399 240 }
2400 else
2401 {
2402 if(rot != 0)
2403 {
2404 //if ( rot == 4096 ) { //translucent
2405 // stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2406 // draw_trans_sprite(bmp, subBmp, dx, dy);
2407 // }
2408 //else {
2409 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2410 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2411 // }
2412 }
2413 else
2414 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2415 }
2416 240 }
2417 else
2418 {
2419
2/2
✓ Branch 0 taken 923090 times.
✓ Branch 1 taken 4722 times.
927812 if(masked)
2420 {
2421
1/2
✓ Branch 0 taken 923090 times.
✗ Branch 1 not taken.
923090 if(rot != 0)
2422 {
2423 //if ( rot == 4096 ) {//translucent
2424 // masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2425 //rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2426
2427 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2428 //rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2429 // draw_trans_sprite(bmp, subBmp, dx, dy);
2430 // }
2431 //else {
2432 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2433 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2434 // }
2435 }
2436 else
2437 923090 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2438 923090 }
2439 else
2440 {
2441
1/2
✓ Branch 0 taken 4722 times.
✗ Branch 1 not taken.
4722 if(rot != 0)
2442 {
2443 //if ( rot == 4096 ) { //translucent
2444 // blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2445 // draw_trans_sprite(bmp, subBmp, dx, dy);
2446 // }
2447 //else {
2448 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
2449 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2450 // }
2451 }
2452 else
2453 4722 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
2454 }
2455 }
2456
2457 //cleanup
2458
1/2
✓ Branch 0 taken 928052 times.
✗ Branch 1 not taken.
928052 if(subBmp)
2459 {
2460 script_drawing_commands.ReleaseSubBitmap(subBmp);
2461 }
2462 928052 }
2463
2464
2465 //Draw]()
2466 void do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
2467 {
2468 /*
2469 //sdci[1]=layer
2470 //sdci[2]=bitmap
2471 //sdci[3]=sourcex
2472 //sdci[4]=sourcey
2473 //sdci[5]=sourcew
2474 //sdci[6]=sourceh
2475 //sdci[7]=destx
2476 //sdci[8]=desty
2477 //sdci[9]=destw
2478 //sdci[10]=desth
2479 //sdci[11]=rotation/angle
2480 //scdi[12] = pivot cx
2481 //sdci[13] = pivot cy
2482 //scdi[14] = effect flags
2483
2484
2485 const int32_t BITDX_NORMAL = 0;
2486 const int32_t BITDX_TRANS = 1; //Translucent
2487 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
2488 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
2489 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
2490 //Note: Some modes cannot be combined. if a combination is not supported, an error
2491 // detailing this will be shown in allegro.log.
2492
2493 //scdi[15] = litcolour
2494 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2495 /not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2496
2497 //sdci[16]=mask
2498
2499 */
2500
2501 int32_t bitmapIndex = sdci[2]/10000;
2502 int32_t sx = sdci[3]/10000;
2503 int32_t sy = sdci[4]/10000;
2504 int32_t sw = sdci[5]/10000;
2505 int32_t sh = sdci[6]/10000;
2506 int32_t dx = sdci[7]/10000;
2507 int32_t dy = sdci[8]/10000;
2508 int32_t dw = sdci[9]/10000;
2509 int32_t dh = sdci[10]/10000;
2510 float rot = sdci[11]/10000;
2511 int32_t cx = sdci[12]/10000;
2512 int32_t cy = sdci[13]/10000;
2513 int32_t mode = sdci[14]/10000;
2514 int32_t litcolour = sdci[15]/10000;
2515 bool masked = (sdci[16] != 0);
2516
2517
2518
2519 //bugfix
2520 sx = vbound(sx, 0, 512);
2521 sy = vbound(sy, 0, 512);
2522 sw = vbound(sw, 0, 512 - sx); //keep the w/h within range as well
2523 sh = vbound(sh, 0, 512 - sy);
2524
2525
2526 if(sx >= ZScriptDrawingRenderTarget::BitmapWidth || sy >= ZScriptDrawingRenderTarget::BitmapHeight)
2527 return;
2528
2529 bool stretched = (sw != dw || sh != dh);
2530
2531 BITMAP *sourceBitmap = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
2532
2533 if(!sourceBitmap)
2534 {
2535 Z_message("Warning: Screen->DrawBitmap(%d) contains invalid data or is not initialized.\n", bitmapIndex);
2536 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
2537 return;
2538 }
2539
2540 BITMAP* subBmp = 0;
2541
2542 /*
2543 if ( bitmapIndex == -1 ) {
2544 blit(bmp, sourceBitmap, sx, sy, 0, 0, dw, dh);
2545 }
2546 */
2547
2548 if(rot != 0 || mode != 0)
2549 {
2550 subBmp = script_drawing_commands.AquireSubBitmap(dw, dh);
2551
2552 if(!subBmp)
2553 {
2554 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
2555 return;
2556 }
2557 }
2558
2559
2560 dx = dx + xoffset;
2561 dy = dy + yoffset;
2562
2563 if(stretched)
2564 {
2565 if(masked) //stretched and masked
2566 {
2567 if ( rot == 0 ) //if not rotated
2568 {
2569 switch(mode)
2570 {
2571 case 1:
2572 //transparent
2573 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2574 draw_trans_sprite(bmp, subBmp, dx, dy);
2575 break;
2576
2577
2578 case 2:
2579 //pivot?
2580 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2581 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2582 //Pivoting requires two more args
2583 break;
2584
2585 case 3:
2586 //pivot + trans
2587 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2588 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2589 break;
2590
2591 case 4:
2592 //flip v
2593 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2594 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2595 break;
2596
2597 case 5:
2598 //trans + v flip
2599 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2600 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2601 break;
2602
2603 case 6:
2604 //pivot + v flip
2605 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2606 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2607 break;
2608
2609 case 8:
2610 //vlip h
2611 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2612 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2613 break;
2614
2615 case 9:
2616 //trans + h flip
2617 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2618 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2619 break;
2620
2621 case 10:
2622 //flip H and pivot
2623 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2624 //return error cannot pivot and h flip
2625 break;
2626
2627 case 12:
2628 //vh flip
2629 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2630 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2631 break;
2632
2633 case 13:
2634 //trans + vh flip
2635 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2636 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2637 break;
2638
2639 case 14:
2640 //pivot and vh flip
2641 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2642 //return error cannot both pivot and vh flip
2643 break;
2644
2645 case 16:
2646 //lit
2647 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2648 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2649 break;
2650
2651 case 18:
2652 //pivot, lit
2653 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2654 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2655 break;
2656
2657 case 20:
2658 //lit + v flip
2659 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2660 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2661 break;
2662
2663 case 22:
2664 //Pivot, vflip, lit
2665 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2666 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2667 break;
2668
2669 case 24:
2670 //lit + h flip
2671 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2672 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2673 break;
2674
2675 case 26:
2676 //pivot + lit + hflip
2677 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2678 //return error cannot pivot, lit, and flip
2679 break;
2680
2681 case 28:
2682 //lit + vh flip
2683 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2684 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2685 break;
2686
2687 case 32: //gouraud
2688 //Probably not wort supporting.
2689 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2690 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2691 break;
2692
2693 case 0:
2694 //no effect
2695 masked_stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2696 break;
2697
2698
2699 default:
2700 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2701
2702
2703 }
2704 } //end if not rotated
2705
2706 if ( rot != 0 ) //if rotated
2707 {
2708 switch(mode)
2709 {
2710 case 1:
2711 //transparent
2712 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2713 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2714
2715 break;
2716
2717 case 2:
2718 //pivot?
2719 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2720 //return an error, cannot both rotate and pivot
2721 break;
2722
2723 case 3:
2724 //pivot + trans
2725 //return an error, cannot both rotate and pivot
2726 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2727 break;
2728
2729 case 4:
2730 //flip v
2731 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2732 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2733 break;
2734
2735 case 5:
2736 //trans + v flip
2737 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2738 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2739 break;
2740
2741 case 6:
2742 //pivot + v flip
2743 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2744 //return an error, cannot both rotate and pivot
2745 break;
2746
2747 case 8:
2748 //flip h
2749 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
2750 //return an error, cannot both rotate and flip H
2751 break;
2752
2753 case 9:
2754 //trans + h flip
2755 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
2756 //return an error, cannot rotate and flip a trans sprite
2757 break;
2758
2759 case 10:
2760 //flip H and pivot
2761 //return error cannot pivot and h flip
2762 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2763 break;
2764
2765 case 12:
2766 //vh flip
2767 //return an error, cannot rotate and VH flip a trans sprite
2768 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2769 break;
2770
2771 case 13:
2772 //trans + vh flip
2773 //return an error, cannot rotate and VH flip a trans sprite
2774 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
2775 break;
2776
2777 case 14:
2778 //pivot and vh flip
2779 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2780 //return error cannot both pivot and vh flip
2781 break;
2782
2783 case 16:
2784 //lit
2785 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2786 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2787 break;
2788
2789 case 18:
2790 //pivot, lit
2791 //return an error, cannot both rotate and pivot
2792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
2793 break;
2794
2795 case 20:
2796 //lit + vflip
2797 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2798 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
2799 break;
2800
2801 case 22:
2802 //Pivot, vflip, lit
2803 //return an error, cannot both rotate and pivot
2804 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2805 break;
2806
2807 case 24:
2808 //lit + h flip
2809 //return an error, cannot both rotate and H flip
2810 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
2811 break;
2812
2813 case 26:
2814 //pivot + lit + hflip
2815 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
2816 //return error cannot pivot, lit, and flip
2817 break;
2818
2819 case 28:
2820 //lit + vh flip
2821 //return an error, cannot both rotate and VH flip
2822 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2823 break;
2824
2825 case 32: //gouraud
2826 //Probably not wort supporting.
2827 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2828 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2829 break;
2830
2831 case 0:
2832 //no effect.
2833 masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2834 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2835 break;
2836
2837 default:
2838 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2839
2840 }
2841 }
2842 } //end if stretched and masked
2843
2844 else //stretched, not masked
2845 {
2846 if ( rot == 0 ) //if not rotated
2847 {
2848 switch(mode) {
2849 case 1:
2850 //transparent
2851 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2852 draw_trans_sprite(bmp, subBmp, dx, dy);
2853 break;
2854
2855
2856 case 2:
2857 //pivot?
2858 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2859 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2860 //Pivoting requires two more args
2861 break;
2862
2863 case 3:
2864 //pivot + trans
2865 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2866 pivot_sprite_trans(bmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
2867 break;
2868
2869 case 4:
2870 //flip v
2871 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2872 draw_sprite_v_flip(bmp, subBmp, dx, dy);
2873 break;
2874
2875 case 5:
2876 //trans + v flip
2877 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2878 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
2879 break;
2880
2881 case 6:
2882 //pivot + v flip
2883 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2884 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
2885 break;
2886
2887 case 8:
2888 //vlip h
2889 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2890 draw_sprite_h_flip(bmp, subBmp, dx, dy);
2891 break;
2892
2893 case 9:
2894 //trans + h flip
2895 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2896 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
2897 break;
2898
2899 case 10:
2900 //flip H and pivot
2901 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
2902 //return error cannot pivot and h flip
2903 break;
2904
2905 case 12:
2906 //vh flip
2907 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2908 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
2909 break;
2910
2911 case 13:
2912 //trans + vh flip
2913 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2914 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
2915 break;
2916
2917 case 14:
2918 //pivot and vh flip
2919 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
2920 //return error cannot both pivot and vh flip
2921 break;
2922
2923 case 16:
2924 //lit
2925 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2926 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
2927 break;
2928
2929 case 18:
2930 //pivot, lit
2931 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2932 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2933 break;
2934
2935 case 20:
2936 //lit + v flip
2937 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2938 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
2939 break;
2940
2941 case 22:
2942 //Pivot, vflip, lit
2943 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2944 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
2945 break;
2946
2947 case 24:
2948 //lit + h flip
2949 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2950 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
2951 break;
2952
2953 case 26:
2954 //pivot + lit + hflip
2955 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
2956 //return error cannot pivot, lit, and flip
2957 break;
2958
2959 case 28:
2960 //lit + vh flip
2961 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2962 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
2963 break;
2964
2965 case 32: //gouraud
2966 //Probably not wort supporting.
2967 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
2968 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
2969 break;
2970
2971 case 0:
2972 //no effect
2973 stretch_blit(sourceBitmap, bmp, sx, sy, sw, sh, dx, dy, dw, dh);
2974 break;
2975
2976
2977 default:
2978 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
2979
2980
2981 }
2982 } //end if not rotated
2983
2984 if ( rot != 0 ) //if rotated
2985 {
2986 switch(mode)
2987 {
2988 case 1:
2989 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
2990 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
2991
2992 break;
2993
2994 case 2:
2995 //pivot?
2996 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
2997 //return an error, cannot both rotate and pivot
2998 break;
2999
3000 case 3:
3001 //pivot + trans
3002 //return an error, cannot both rotate and pivot
3003 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3004 break;
3005
3006 case 4:
3007 //flip v
3008 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3009 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3010 break;
3011
3012 case 5:
3013 //trans + v flip
3014 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3015 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3016 break;
3017
3018 case 6:
3019 //pivot + v flip
3020 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3021 //return an error, cannot both rotate and pivot
3022 break;
3023
3024 case 8:
3025 //flip h
3026 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3027 //return an error, cannot both rotate and flip H
3028 break;
3029
3030 case 9:
3031 //trans + h flip
3032 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3033 //return an error, cannot rotate and flip a trans sprite
3034 break;
3035
3036 case 10:
3037 //flip H and pivot
3038 //return error cannot pivot and h flip
3039 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3040 break;
3041
3042 case 12:
3043 //vh flip
3044 //return an error, cannot rotate and VH flip a trans sprite
3045 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3046 break;
3047
3048 case 13:
3049 //trans + vh flip
3050 //return an error, cannot rotate and VH flip a trans sprite
3051 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3052 break;
3053
3054 case 14:
3055 //pivot and vh flip
3056 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3057 //return error cannot both pivot and vh flip
3058 break;
3059
3060 case 16:
3061 //lit
3062 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3063 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3064 break;
3065
3066 case 18:
3067 //pivot, lit
3068 //return an error, cannot both rotate and pivot
3069 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3070 break;
3071
3072 case 20:
3073 //lit + vflip
3074 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
3075 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3076 break;
3077
3078 case 22:
3079 //Pivot, vflip, lit
3080 //return an error, cannot both rotate and pivot
3081 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3082 break;
3083
3084 case 24:
3085 //lit + h flip
3086 //return an error, cannot both rotate and H flip
3087 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3088 break;
3089
3090 case 26:
3091 //pivot + lit + hflip
3092 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3093 //return error cannot pivot, lit, and flip
3094 break;
3095
3096 case 28:
3097 //lit + vh flip
3098 //return an error, cannot both rotate and VH flip
3099 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3100 break;
3101
3102 case 32: //gouraud
3103 //Probably not wort supporting.
3104 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3105 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3106 break;
3107
3108 case 0:
3109 //no effect.
3110 stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3111 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3112 break;
3113
3114 default:
3115 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3116
3117 }
3118 }
3119
3120 } //end if stretched, but not masked
3121 }
3122 else //not stretched
3123 {
3124
3125 if(masked) //if masked, but not stretched
3126 {
3127
3128 if ( rot == 0 ) //if not rotated
3129 {
3130 switch(mode)
3131 {
3132 case 1:
3133 //transparent
3134 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3135 draw_trans_sprite(bmp, subBmp, dx, dy);
3136 break;
3137
3138
3139 case 2:
3140 //pivot?
3141 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3142 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3143 //Pivoting requires two more args
3144 break;
3145
3146 case 3:
3147 //pivot + trans
3148 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3149 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3150 break;
3151
3152 case 4:
3153 //flip v
3154 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3155 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3156 break;
3157
3158 case 5:
3159 //trans + v flip
3160 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3161 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3162 break;
3163
3164 case 6:
3165 //pivot + v flip
3166 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3167 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3168 break;
3169
3170 case 8:
3171 //vlip h
3172 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3173 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3174 break;
3175
3176 case 9:
3177 //trans + h flip
3178 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3179 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3180 break;
3181
3182 case 10:
3183 //flip H and pivot
3184 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3185 //return error cannot pivot and h flip
3186 break;
3187
3188 case 12:
3189 //vh flip
3190 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3191 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3192 break;
3193
3194 case 13:
3195 //trans + vh flip
3196 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3197 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3198 break;
3199
3200 case 14:
3201 //pivot and vh flip
3202 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3203 //return error cannot both pivot and vh flip
3204 break;
3205
3206 case 16:
3207 //lit
3208 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3209 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3210 break;
3211
3212 case 18:
3213 //pivot, lit
3214 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3215 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3216 break;
3217
3218 case 20:
3219 //lit + v flip
3220 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3221 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3222 break;
3223
3224 case 22:
3225 //Pivot, vflip, lit
3226 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3227 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3228 break;
3229
3230 case 24:
3231 //lit + h flip
3232 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3233 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3234 break;
3235
3236 case 26:
3237 //pivot + lit + hflip
3238 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3239 //return error cannot pivot, lit, and flip
3240 break;
3241
3242 case 28:
3243 //lit + vh flip
3244 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3245 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3246 break;
3247
3248 case 32: //gouraud
3249 //Probably not wort supporting.
3250 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3251 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3252 break;
3253
3254 case 0:
3255 //no effect
3256 masked_blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3257 break;
3258
3259
3260 default:
3261 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3262
3263
3264 }
3265 } //end if not rotated
3266
3267 if ( rot != 0 ) //if rotated
3268 {
3269 switch(mode)
3270 {
3271 case 1:
3272 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //transparent
3273 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3274
3275 break;
3276
3277 case 2:
3278 //pivot?
3279 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3280 //return an error, cannot both rotate and pivot
3281 break;
3282
3283 case 3:
3284 //pivot + trans
3285 //return an error, cannot both rotate and pivot
3286 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3287 break;
3288
3289 case 4:
3290 //flip v
3291 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3292 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3293 break;
3294
3295 case 5:
3296 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
3297 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3298 break;
3299
3300 case 6:
3301 //pivot + v flip
3302 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3303 //return an error, cannot both rotate and pivot
3304 break;
3305
3306 case 8:
3307 //flip h
3308 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3309 //return an error, cannot both rotate and flip H
3310 break;
3311
3312 case 9:
3313 //trans + h flip
3314 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3315 //return an error, cannot rotate and flip a trans sprite
3316 break;
3317
3318 case 10:
3319 //flip H and pivot
3320 //return error cannot pivot and h flip
3321 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3322 break;
3323
3324 case 12:
3325 //vh flip
3326 //return an error, cannot rotate and VH flip a trans sprite
3327 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3328 break;
3329
3330 case 13:
3331 //trans + vh flip
3332 //return an error, cannot rotate and VH flip a trans sprite
3333 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3334 break;
3335
3336 case 14:
3337 //pivot and vh flip
3338 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3339 //return error cannot both pivot and vh flip
3340 break;
3341
3342 case 16:
3343 //lit
3344 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3345 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3346 break;
3347
3348 case 18:
3349 //pivot, lit
3350 //return an error, cannot both rotate and pivot
3351 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3352 break;
3353
3354 case 20:
3355 //lit + vflip
3356 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3357 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3358 break;
3359
3360 case 22:
3361 //Pivot, vflip, lit
3362 //return an error, cannot both rotate and pivot
3363 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3364 break;
3365
3366 case 24:
3367 //lit + h flip
3368 //return an error, cannot both rotate and H flip
3369 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3370 break;
3371
3372 case 26:
3373 //pivot + lit + hflip
3374 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3375 //return error cannot pivot, lit, and flip
3376 break;
3377
3378 case 28:
3379 //lit + vh flip
3380 //return an error, cannot both rotate and VH flip
3381 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3382 break;
3383
3384 case 32: //gouraud
3385 //Probably not wort supporting.
3386 //stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
3387 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3388 break;
3389
3390 case 0:
3391 //no effect.
3392 masked_blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3393 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3394 break;
3395
3396 default:
3397 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3398
3399 }
3400 } //end rtated, masked
3401 } //end if masked
3402
3403 else //not masked, and not stretched; just blit
3404 {
3405
3406 if ( rot == 0 ) //if not rotated
3407 {
3408 switch(mode)
3409 {
3410 case 1:
3411 //transparent
3412 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3413 draw_trans_sprite(bmp, subBmp, dx, dy);
3414 break;
3415
3416
3417 case 2:
3418 //pivot?
3419 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3420 pivot_sprite(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3421 //Pivoting requires two more args
3422 break;
3423
3424 case 3:
3425 //pivot + trans
3426 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3427 pivot_sprite_trans(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3428 break;
3429
3430 case 4:
3431 //flip v
3432 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3433 draw_sprite_v_flip(bmp, subBmp, dx, dy);
3434 break;
3435
3436 case 5:
3437 //trans + v flip
3438 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3439 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
3440 break;
3441
3442 case 6:
3443 //pivot + v flip
3444 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3445 pivot_sprite_v_flip(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
3446 break;
3447
3448 case 8:
3449 //vlip h
3450 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3451 draw_sprite_h_flip(bmp, subBmp, dx, dy);
3452 break;
3453
3454 case 9:
3455 //trans + h flip
3456 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3457 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
3458 break;
3459
3460 case 10:
3461 //flip H and pivot
3462 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3463 //return error cannot pivot and h flip
3464 break;
3465
3466 case 12:
3467 //vh flip
3468 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3469 draw_sprite_vh_flip(bmp, subBmp, dx, dy);
3470 break;
3471
3472 case 13:
3473 //trans + vh flip
3474 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3475 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
3476 break;
3477
3478 case 14:
3479 //pivot and vh flip
3480 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3481 //return error cannot both pivot and vh flip
3482 break;
3483
3484 case 16:
3485 //lit
3486 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3487 draw_lit_sprite(bmp, subBmp, dx, dy, litcolour);
3488 break;
3489
3490 case 18:
3491 //pivot, lit
3492 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3493 pivot_sprite_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3494 break;
3495
3496 case 20:
3497 //lit + v flip
3498 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3499 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
3500 break;
3501
3502 case 22:
3503 //Pivot, vflip, lit
3504 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3505 pivot_sprite_v_flip_lit(bmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
3506 break;
3507
3508 case 24:
3509 //lit + h flip
3510 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3511 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
3512 break;
3513
3514 case 26:
3515 //pivot + lit + hflip
3516 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
3517 //return error cannot pivot, lit, and flip
3518 break;
3519
3520 case 28:
3521 //lit + vh flip
3522 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3523 draw_sprite_ex(bmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
3524 break;
3525
3526 case 32: //gouraud
3527 //Probably not wort supporting.
3528 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3529 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3530 break;
3531
3532 case 0:
3533 //no effect
3534 blit(sourceBitmap, bmp, sx, sy, dx, dy, dw, dh);
3535 break;
3536
3537
3538 default:
3539 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3540
3541
3542 }
3543 } //end if not rotated
3544
3545 if ( rot != 0 ) //if rotated
3546 {
3547 switch(mode)
3548 {
3549 case 1:
3550 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);//transparent
3551 rotate_sprite_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3552
3553 break;
3554
3555 case 2:
3556 //pivot?
3557 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3558 //return an error, cannot both rotate and pivot
3559 break;
3560
3561 case 3:
3562 //pivot + trans
3563 //return an error, cannot both rotate and pivot
3564 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3565 break;
3566
3567 case 4:
3568 //flip v
3569 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3570 rotate_sprite_v_flip(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3571 break;
3572
3573 case 5:
3574 //trans + v flip
3575 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3576 rotate_sprite_v_flip_trans(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3577 break;
3578
3579 case 6:
3580 //pivot + v flip
3581 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3582 //return an error, cannot both rotate and pivot
3583 break;
3584
3585 case 8:
3586 //flip h
3587 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
3588 //return an error, cannot both rotate and flip H
3589 break;
3590
3591 case 9:
3592 //trans + h flip
3593 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
3594 //return an error, cannot rotate and flip a trans sprite
3595 break;
3596
3597 case 10:
3598 //flip H and pivot
3599 //return error cannot pivot and h flip
3600 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
3601 break;
3602
3603 case 12:
3604 //vh flip
3605 //return an error, cannot rotate and VH flip a trans sprite
3606 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3607 break;
3608
3609 case 13:
3610 //trans + vh flip
3611 //return an error, cannot rotate and VH flip a trans sprite
3612 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
3613 break;
3614
3615 case 14:
3616 //pivot and vh flip
3617 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3618 //return error cannot both pivot and vh flip
3619 break;
3620
3621 case 16:
3622 //lit
3623 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3624 rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3625 break;
3626
3627 case 18:
3628 //pivot, lit
3629 //return an error, cannot both rotate and pivot
3630 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
3631 break;
3632
3633 case 20:
3634 //lit + vflip
3635 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3636 rotate_sprite_v_flip_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
3637 break;
3638
3639 case 22:
3640 //Pivot, vflip, lit
3641 //return an error, cannot both rotate and pivot
3642 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
3643 break;
3644
3645 case 24:
3646 //lit + h flip
3647 //return an error, cannot both rotate and H flip
3648 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
3649 break;
3650
3651 case 26:
3652 //pivot + lit + hflip
3653 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
3654 //return error cannot pivot, lit, and flip
3655 break;
3656
3657 case 28:
3658 //lit + vh flip
3659 //return an error, cannot both rotate and VH flip
3660 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
3661 break;
3662
3663 case 32: //gouraud
3664 //Probably not wort supporting.
3665 //blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3666 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
3667 break;
3668
3669 case 0:
3670 //no effect.
3671 blit(sourceBitmap, subBmp, sx, sy, 0, 0, dw, dh);
3672 rotate_sprite(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
3673 break;
3674
3675 default:
3676 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
3677
3678 }
3679 } //end if rotated
3680 } //end if not masked
3681 } //end if not stretched
3682
3683 //cleanup
3684 if(subBmp)
3685 {
3686 script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
3687 }
3688 }
3689
3690
3691 void do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3692 {
3693 //sdci[1]=layer
3694 //sdci[2]=pos[12]
3695 //sdci[3]=uv[8]
3696 //sdci[4]=color[4]
3697 //sdci[5]=size[2]
3698 //sdci[6]=flip
3699 //sdci[7]=tile/combo
3700 //sdci[8]=polytype
3701
3702 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3703
3704 if(!v_ptr)
3705 {
3706 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
3707 return;
3708 }
3709
3710 std::vector<int32_t> &v = *v_ptr;
3711
3712 if(v.empty())
3713 return;
3714
3715 int32_t* pos = &v[0];
3716 int32_t* uv = &v[12];
3717 int32_t* col = &v[20];
3718 int32_t* size = &v[24];
3719
3720 int32_t w = size[0]; //magic numerical constants... yuck.
3721 int32_t h = size[1];
3722 int32_t flip = (sdci[6]/10000)&3;
3723 int32_t tile = sdci[7]/10000;
3724 int32_t polytype = sdci[8]/10000;
3725
3726 polytype = vbound(polytype, 0, 14);
3727
3728 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3729 {
3730 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3731 return; //non power of two error
3732 }
3733
3734 int32_t tex_width = w*16;
3735 int32_t tex_height = h*16;
3736
3737 bool mustDestroyBmp = false;
3738 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3739
3740 if(!tex)
3741 {
3742 mustDestroyBmp = true;
3743 tex = create_bitmap_ex(8, tex_width, tex_height);
3744 clear_bitmap(tex);
3745 }
3746
3747 if(tile > 0) // TILE
3748 {
3749 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3750 }
3751 else // COMBO
3752 {
3753 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3754 const int32_t tiletodraw = combo_tile(c, 0, 0);
3755 flip = flip ^ c.flip;
3756
3757 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3758 }
3759
3760 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3761 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3762 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3763 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
3764
3765 quad3d_f(bmp, polytype, tex, &V1, &V2, &V3, &V4);
3766
3767 if(mustDestroyBmp)
3768 destroy_bitmap(tex);
3769
3770 }
3771
3772
3773
3774 void do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3775 {
3776 //sdci[1]=layer
3777 //sdci[2]=pos[9]
3778 //sdci[3]=uv[6]
3779 //sdci[4]=color[3]
3780 //sdci[5]=size[2]
3781 //sdci[6]=flip
3782 //sdci[7]=tile/combo
3783 //sdci[8]=polytype
3784
3785 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
3786
3787 if(!v_ptr)
3788 {
3789 al_trace("Triange3d: Vector pointer is null! Internal error. \n");
3790 return;
3791 }
3792
3793 std::vector<int32_t> &v = *v_ptr;
3794
3795 if(v.empty())
3796 return;
3797
3798 int32_t* pos = &v[0];
3799 int32_t* uv = &v[9];
3800 int32_t* col = &v[15];
3801 int32_t* size = &v[18];
3802
3803 int32_t w = size[0]; //magic numerical constants... yuck.
3804 int32_t h = size[1];
3805 int32_t flip = (sdci[6]/10000)&3;
3806 int32_t tile = sdci[7]/10000;
3807 int32_t polytype = sdci[8]/10000;
3808
3809 polytype = vbound(polytype, 0, 14);
3810
3811 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
3812 {
3813 Z_message("Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
3814 return; //non power of two error
3815 }
3816
3817 int32_t tex_width = w*16;
3818 int32_t tex_height = h*16;
3819
3820 bool mustDestroyBmp = false;
3821 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
3822
3823 if(!tex)
3824 {
3825 mustDestroyBmp = true;
3826 tex = create_bitmap_ex(8, tex_width, tex_height);
3827 clear_bitmap(tex);
3828 }
3829
3830 if(tile > 0) // TILE
3831 {
3832 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
3833 }
3834 else // COMBO
3835 {
3836 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
3837 const int32_t tiletodraw = combo_tile(c, 0, 0);
3838 flip = flip ^ c.flip;
3839
3840 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
3841 }
3842
3843 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
3844 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
3845 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
3846
3847 triangle3d_f(bmp, polytype, tex, &V1, &V2, &V3);
3848
3849 if(mustDestroyBmp)
3850 destroy_bitmap(tex);
3851
3852 }
3853
3854 7971 void bmp_do_rectr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3855 {
3856 //Z_scripterrlog("rect sdci[13] is: %d\n", sdci[13]);
3857 //sdci[1]=layer
3858 //sdci[2]=x
3859 //sdci[3]=y
3860 //sdci[4]=x2
3861 //sdci[5]=y2
3862 //sdci[6]=color
3863 //sdci[7]=scale factor
3864 //sdci[8]=rotation anchor x
3865 //sdci[9]=rotation anchor y
3866 //sdci[10]=rotation angle
3867 //sdci[11]=fill
3868 //sdci[12]=opacity
3869 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
3870
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7]==0) //scale
3871 {
3872 return;
3873 }
3874
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7971 times.
7971 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3875 {
3876 Z_scripterrlog("bitmap->Rectangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3877 return;
3878 }
3879 7971 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
3880
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if ( refbmp == NULL ) return;
3881
3882
2/4
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 7971 times.
7971 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3883
3884 7971 int32_t x1=sdci[2]/10000;
3885 7971 int32_t y1=sdci[3]/10000;
3886 7971 int32_t x2=sdci[4]/10000;
3887 7971 int32_t y2=sdci[5]/10000;
3888
3889
3890
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(x1>x2)
3891 {
3892 4 zc_swap(x1,x2);
3893 4 }
3894
3895
2/2
✓ Branch 0 taken 7967 times.
✓ Branch 1 taken 4 times.
7971 if(y1>y2)
3896 {
3897 4 zc_swap(y1,y2);
3898 4 }
3899
3900
1/2
✓ Branch 0 taken 7971 times.
✗ Branch 1 not taken.
7971 if(sdci[7] != 10000)
3901 {
3902 int32_t w=x2-x1+1;
3903 int32_t h=y2-y1+1;
3904 int32_t w2=(w*sdci[7])/10000;
3905 int32_t h2=(h*sdci[7])/10000;
3906 x1=x1-((w2-w)/2);
3907 x2=x2+((w2-w)/2);
3908 y1=y1-((h2-h)/2);
3909 y2=y2+((h2-h)/2);
3910 }
3911
3912 7971 int32_t color=sdci[6]/10000;
3913
3914
2/2
✓ Branch 0 taken 7843 times.
✓ Branch 1 taken 128 times.
7971 if(sdci[12]/10000<=127) //translucent
3915 {
3916 128 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
3917 128 }
3918
3919
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 7875 times.
7971 if(sdci[10]==0) //no rotation
3920 {
3921
2/2
✓ Branch 0 taken 7863 times.
✓ Branch 1 taken 12 times.
7875 if(sdci[11]) //filled
3922 {
3923 7863 rectfill(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3924 7863 }
3925 else //outline
3926 {
3927 12 rect(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
3928 }
3929 7875 }
3930 else //rotate
3931 {
3932 int32_t xy[16];
3933 96 int32_t rx=sdci[8]/10000;
3934 96 int32_t ry=sdci[9]/10000;
3935 96 fixed ra1=itofix(sdci[10]%10000)/10000;
3936 96 fixed ra2=itofix(sdci[10]/10000);
3937 96 fixed ra=ra1+ra2;
3938 96 ra = (ra/360)*256;
3939
3940 96 fixed fcosa = fixcos(ra);
3941 96 fixed fsina = fixsin(ra);
3942
3943 96 xy[ 0]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry))); //x1
3944 96 xy[ 1]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry))); //y1
3945 96 xy[ 2]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y1 - ry))); //x2
3946 96 xy[ 3]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y1 - ry))); //y1
3947 96 xy[ 4]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry))); //x2
3948 96 xy[ 5]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry))); //y2
3949 96 xy[ 6]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y2 - ry))); //x1
3950 96 xy[ 7]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y2 - ry))); //y2
3951 96 xy[ 8]=xoffset+rx + fixtoi((fcosa * (x1 - rx) - fsina * (y1 - ry + 1))); //x1
3952 96 xy[ 9]=yoffset+ry + fixtoi((fsina * (x1 - rx) + fcosa * (y1 - ry + 1))); //y1
3953 96 xy[10]=xoffset+rx + fixtoi((fcosa * (x2 - rx - 1) - fsina * (y1 - ry))); //x2
3954 96 xy[11]=yoffset+ry + fixtoi((fsina * (x2 - rx - 1) + fcosa * (y1 - ry))); //y1
3955 96 xy[12]=xoffset+rx + fixtoi((fcosa * (x2 - rx) - fsina * (y2 - ry - 1))); //x2
3956 96 xy[13]=yoffset+ry + fixtoi((fsina * (x2 - rx) + fcosa * (y2 - ry - 1))); //y2
3957 96 xy[14]=xoffset+rx + fixtoi((fcosa * (x1 - rx + 1) - fsina * (y2 - ry))); //x1
3958 96 xy[15]=yoffset+ry + fixtoi((fsina * (x1 - rx + 1) + fcosa * (y2 - ry))); //y2
3959
3960
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 if(sdci[11]) //filled
3961 {
3962 96 polygon(refbmp, 4, xy, color);
3963 96 }
3964 else //outline
3965 {
3966 line(refbmp, xy[0], xy[1], xy[10], xy[11], color);
3967 line(refbmp, xy[2], xy[3], xy[12], xy[13], color);
3968 line(refbmp, xy[4], xy[5], xy[14], xy[15], color);
3969 line(refbmp, xy[6], xy[7], xy[ 8], xy[ 9], color);
3970 }
3971 }
3972
3973 7971 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
3974 7971 }
3975
3976 void bmp_do_framer(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
3977 {
3978 //sdci[1]=layer
3979 //sdci[2]=x
3980 //sdci[3]=y
3981 //sdci[4]=tile
3982 //sdci[5]=cset
3983 //sdci[6]=width
3984 //sdci[7]=height
3985 //sdci[8]=overlay
3986 //sdci[9]=opacity
3987
3988 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
3989 {
3990 Z_scripterrlog("bitmap->DrawFrame() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
3991 return;
3992 }
3993 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
3994 if ( refbmp == NULL ) return;
3995
3996 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
3997
3998 int32_t x=sdci[2]/10000;
3999 int32_t y=sdci[3]/10000;
4000
4001 int32_t tile=sdci[4]/10000;
4002 int32_t cs=sdci[5]/10000;
4003 int32_t w=sdci[6]/10000;
4004 int32_t h=sdci[7]/10000;
4005 bool overlay=sdci[8];
4006 bool trans=(sdci[9]/10000<=127);
4007
4008 frame2x2(refbmp, x + xoffset, y + yoffset, tile, cs, w, h, 0, overlay, trans);
4009 }
4010
4011
4012 148823 void bmp_do_circler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4013 {
4014 //sdci[1]=layer
4015 //sdci[2]=x
4016 //sdci[3]=y
4017 //sdci[4]=radius
4018 //sdci[5]=color
4019 //sdci[6]=scale factor
4020 //sdci[7]=rotation anchor x
4021 //sdci[8]=rotation anchor y
4022 //sdci[9]=rotation angle
4023 //sdci[10]=fill
4024 //sdci[11]=opacity
4025 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4026
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6]==0) //scale
4027 {
4028 return;
4029 }
4030
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
148823 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4031 {
4032 Z_scripterrlog("bitmap->Circle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4033 return;
4034 }
4035 148823 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4036
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if ( refbmp == NULL ) return;
4037
4038
2/4
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 148823 times.
148823 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4039
4040 148823 int32_t x1=sdci[2]/10000;
4041 148823 int32_t y1=sdci[3]/10000;
4042 148823 qword r=sdci[4];
4043
4044
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[6] != 10000)
4045 {
4046 r*=sdci[6];
4047 r/=10000;
4048 }
4049
4050 148823 r/=10000;
4051 148823 int32_t color=sdci[5]/10000;
4052
4053
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[11]/10000<=127) //translucent
4054 {
4055 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4056 }
4057
4058
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 148823 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
148823 if(sdci[9]!=0&&(sdci[2]!=sdci[7]||sdci[3]!=sdci[8])) //rotation
4059 {
4060 int32_t xy[2];
4061 int32_t rx=sdci[7]/10000;
4062 int32_t ry=sdci[8]/10000;
4063 fixed ra1=itofix(sdci[9]%10000)/10000;
4064 fixed ra2=itofix(sdci[9]/10000);
4065 fixed ra=ra1+ra2;
4066 ra = (ra/360)*256;
4067
4068 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4069 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4070 x1=xy[0];
4071 y1=xy[1];
4072 }
4073
4074
1/2
✓ Branch 0 taken 148823 times.
✗ Branch 1 not taken.
148823 if(sdci[10]) //filled
4075 {
4076 148823 circlefill(refbmp, x1+xoffset, y1+yoffset, r, color);
4077 148823 }
4078 else //outline
4079 {
4080 circle(refbmp, x1+xoffset, y1+yoffset, r, color);
4081 }
4082
4083 148823 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4084 148823 }
4085
4086
4087 void bmp_do_arcr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4088 {
4089 //sdci[1]=layer
4090 //sdci[2]=x
4091 //sdci[3]=y
4092 //sdci[4]=radius
4093 //sdci[5]=start angle
4094 //sdci[6]=end angle
4095 //sdci[7]=color
4096 //sdci[8]=scale factor
4097 //sdci[9]=rotation anchor x
4098 //sdci[10]=rotation anchor y
4099 //sdci[11]=rotation angle
4100 //sdci[12]=closed
4101 //sdci[13]=fill
4102 //sdci[14]=opacity
4103 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4104
4105 if(sdci[8]==0) //scale
4106 {
4107 return;
4108 }
4109 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4110 {
4111 Z_scripterrlog("bitmap->Arc() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4112 return;
4113 }
4114 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4115 if ( refbmp == NULL ) return;
4116
4117 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4118
4119 int32_t cx=sdci[2]/10000;
4120 int32_t cy=sdci[3]/10000;
4121 qword r=sdci[4];
4122
4123 if(sdci[8] != 10000)
4124 {
4125 r*=sdci[8];
4126 r/=10000;
4127 }
4128
4129 r/=10000;
4130
4131 int32_t color=sdci[7]/10000;
4132
4133 fixed ra1=itofix(sdci[11]%10000)/10000;
4134 fixed ra2=itofix(sdci[11]/10000);
4135 fixed ra=ra1+ra2;
4136 ra = (ra/360)*256;
4137
4138
4139 fixed a1=itofix(sdci[5]%10000)/10000;
4140 fixed a2=itofix(sdci[5]/10000);
4141 fixed sa=a1+a2;
4142 sa = (sa/360)*256;
4143
4144 a1=itofix(sdci[6]%10000)/10000;
4145 a2=itofix(sdci[6]/10000);
4146 fixed ea=a1+a2;
4147 ea = (ea/360)*256;
4148
4149 if(sdci[11]!=0) //rotation
4150 {
4151 int32_t rx=sdci[9]/10000;
4152 int32_t ry=sdci[10]/10000;
4153
4154 cx=rx + fixtoi((fixcos(ra) * (cx - rx) - fixsin(ra) * (cy - ry))); //x1
4155 cy=ry + fixtoi((fixsin(ra) * (cx - rx) + fixcos(ra) * (cy - ry))); //y1
4156 ea-=ra;
4157 sa-=ra;
4158 }
4159
4160 int32_t fx=cx+fixtoi(fixcos(-(ea+sa)/2)*r/2);
4161 int32_t fy=cy+fixtoi(fixsin(-(ea+sa)/2)*r/2);
4162
4163 if(sdci[12]) //closed
4164 {
4165 if(sdci[13]) //filled
4166 {
4167 clear_bitmap(prim_bmp);
4168 arc(prim_bmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4169 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4170 line(prim_bmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4171 int fillx = zc_max(0,fx)+xoffset;
4172 int filly = zc_max(0,fy)+yoffset;
4173 zprint2("bitmap->Arc fill at prim_bmp (%d,%d) - 512x512\n", fillx, filly);
4174 floodfill(prim_bmp, fillx, filly, color);
4175
4176 if(sdci[14]/10000<=127) //translucent
4177 {
4178 draw_trans_sprite(refbmp, prim_bmp, 0,0);
4179 }
4180 else
4181 {
4182 draw_sprite(refbmp, prim_bmp, 0,0);
4183 }
4184 }
4185 else
4186 {
4187 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4188 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-sa)*r), cy+yoffset+fixtoi(fixsin(-sa)*r), color);
4189 line(refbmp, cx+xoffset, cy+yoffset, cx+xoffset+fixtoi(fixcos(-ea)*r), cy+yoffset+fixtoi(fixsin(-ea)*r), color);
4190 }
4191 }
4192 else
4193 {
4194 if(sdci[14]/10000<=127) //translucent
4195 {
4196 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4197 }
4198
4199 arc(refbmp, cx+xoffset, cy+yoffset, sa, ea, int32_t(r), color);
4200 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4201 }
4202 }
4203
4204
4205 502 void bmp_do_ellipser(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4206 {
4207 //sdci[1]=layer
4208 //sdci[2]=x
4209 //sdci[3]=y
4210 //sdci[4]=radiusx
4211 //sdci[5]=radiusy
4212 //sdci[6]=color
4213 //sdci[7]=scale factor
4214 //sdci[8]=rotation anchor x
4215 //sdci[9]=rotation anchor y
4216 //sdci[10]=rotation angle
4217 //sdci[11]=fill
4218 //sdci[12]=opacity
4219 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4220
4221
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if(sdci[7]==0) //scale
4222 {
4223 return;
4224 }
4225
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 502 times.
502 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4226 {
4227 Z_scripterrlog("bitmap->Ellipse() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4228 return;
4229 }
4230 502 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4231
1/2
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
502 if ( refbmp == NULL ) return;
4232
4233 502 int32_t x1=sdci[2]/10000;
4234 502 int32_t y1=sdci[3]/10000;
4235 502 int32_t radx=sdci[4]/10000;
4236 502 radx*=sdci[7]/10000;
4237 502 int32_t rady=sdci[5]/10000;
4238 502 rady*=sdci[7]/10000;
4239 502 int32_t color=sdci[6]/10000;
4240 502 float rotation = sdci[10]/10000;
4241
4242 502 int32_t rx=sdci[8]/10000;
4243 502 int32_t ry=sdci[9]/10000;
4244 502 fixed ra1=itofix(sdci[10]%10000)/10000;
4245 502 fixed ra2=itofix(sdci[10]/10000);
4246 502 fixed ra=ra1+ra2;
4247 502 ra = (ra/360)*256;
4248
4249
2/4
✓ Branch 0 taken 502 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 502 times.
✗ Branch 3 not taken.
502 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4250
4251 int32_t xy[2];
4252 502 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4253 502 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4254 502 x1=xy[0];
4255 502 y1=xy[1];
4256
4257
6/8
✓ Branch 0 taken 498 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 494 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 494 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 494 times.
502 if(radx<1||rady<1||radx>255||rady>255) return;
4258
4259 494 BITMAP* bitty = script_drawing_commands.AquireSubBitmap(radx*2+1, rady*2+1);
4260
4261
2/4
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 494 times.
494 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4262
4263
1/2
✓ Branch 0 taken 494 times.
✗ Branch 1 not taken.
494 if(sdci[11]) //filled
4264 {
4265
4266
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 494 times.
494 if(sdci[12]/10000<128) //translucent
4267 {
4268 clear_bitmap(prim_bmp);
4269 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4270 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4271 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4272 }
4273 else // no opacity
4274 {
4275
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 ellipsefill(bitty, radx, rady, radx, rady, color==0?255:color);
4276 494 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4277 }
4278 494 }
4279 else //not filled
4280 {
4281 if(sdci[12]/10000<128) //translucent
4282 {
4283 clear_bitmap(prim_bmp);
4284 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4285 rotate_sprite(prim_bmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4286 draw_trans_sprite(refbmp, prim_bmp, 0, 0);
4287 }
4288 else // no opacity
4289 {
4290 ellipse(bitty, radx, rady, radx, rady, color==0?255:color);
4291 rotate_sprite(refbmp, bitty, x1+xoffset-radx,y1+yoffset-rady, degrees_to_fixed(rotation));
4292 }
4293 }
4294
4295 // Since 0 is the transparent color, the stuff above will fail if the ellipse color is also 0.
4296 // Instead, it uses color 255 and replaces it afterward. That'll also screw up color 255 around
4297 // the ellipse, but it shouldn't be used anyway.
4298
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 62 times.
494 if(color==0)
4299 {
4300 // This is very slow, so check the smallest possible square
4301
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endx=zc_min(bmp->w-1, x1+zc_max(radx, rady));
4302
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 62 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 62 times.
62 int32_t endy=zc_min(bmp->h-1, y1+zc_max(radx, rady));
4303
4304
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 60 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 4430 times.
✓ Branch 7 taken 62 times.
4492 for(int32_t y=zc_max(0, y1-zc_max(radx, rady)); y<=endy; y++)
4305
6/8
✗ Branch 0 not taken.
✓ Branch 1 taken 4430 times.
✓ Branch 2 taken 1086 times.
✓ Branch 3 taken 3344 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1086 times.
✓ Branch 6 taken 467774 times.
✓ Branch 7 taken 4430 times.
472204 for(int32_t x=zc_max(0, x1-zc_max(radx, rady)); x<=endx; x++)
4306
2/2
✓ Branch 0 taken 238992 times.
✓ Branch 1 taken 228782 times.
696556 if(getpixel(refbmp, x, y)==255)
4307 233212 putpixel(refbmp, x, y, 0);
4308 62 }
4309
4310 494 script_drawing_commands.ReleaseSubBitmap(bitty);
4311 502 }
4312
4313
4314 144 void bmp_do_liner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4315 {
4316 //sdci[1]=layer
4317 //sdci[2]=x
4318 //sdci[3]=y
4319 //sdci[4]=x2
4320 //sdci[5]=y2
4321 //sdci[6]=color
4322 //sdci[7]=scale factor
4323 //sdci[8]=rotation anchor x
4324 //sdci[9]=rotation anchor y
4325 //sdci[10]=rotation angle
4326 //sdci[11]=opacity
4327 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4328
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7]==0) //scale
4329 {
4330 return;
4331 }
4332
4333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 144 times.
144 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4334 {
4335 Z_scripterrlog("bitmap->Line() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4336 return;
4337 }
4338
4339 144 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4340
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if ( refbmp == NULL ) return;
4341
4342 144 int32_t x1=sdci[2]/10000;
4343 144 int32_t y1=sdci[3]/10000;
4344 144 int32_t x2=sdci[4]/10000;
4345 144 int32_t y2=sdci[5]/10000;
4346
4347
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[7] != 10000)
4348 {
4349 int32_t w=x2-x1+1;
4350 int32_t h=y2-y1+1;
4351 int32_t w2=int32_t(w*((double)sdci[7]/10000.0));
4352 int32_t h2=int32_t(h*((double)sdci[7]/10000.0));
4353 x1=x1-((w2-w)/2);
4354 x2=x2+((w2-w)/2);
4355 y1=y1-((h2-h)/2);
4356 y2=y2+((h2-h)/2);
4357 }
4358
4359 144 int32_t color=sdci[6]/10000;
4360
4361
2/4
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 144 times.
144 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4362
4363
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[11]/10000<=127) //translucent
4364 {
4365 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4366 }
4367
4368
1/2
✓ Branch 0 taken 144 times.
✗ Branch 1 not taken.
144 if(sdci[10]!=0) //rotation
4369 {
4370 int32_t xy[4];
4371 int32_t rx=sdci[8]/10000;
4372 int32_t ry=sdci[9]/10000;
4373 fixed ra1=itofix(sdci[10]%10000)/10000;
4374 fixed ra2=itofix(sdci[10]/10000);
4375 fixed ra=ra1+ra2;
4376
4377 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4378 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4379 xy[ 2]=rx + fixtoi((fixcos(ra) * (x2 - rx) - fixsin(ra) * (y2 - ry))); //x2
4380 xy[ 3]=ry + fixtoi((fixsin(ra) * (x2 - rx) + fixcos(ra) * (y2 - ry))); //y2
4381 x1=xy[0];
4382 y1=xy[1];
4383 x2=xy[2];
4384 y2=xy[3];
4385 }
4386
4387 144 line(refbmp, x1+xoffset, y1+yoffset, x2+xoffset, y2+yoffset, color);
4388 144 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4389 144 }
4390
4391
4392 void bmp_do_spliner(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4393 {
4394 /* layer, x1, y1, x2, y2, x3, y3, x4, y4, color, opacity */
4395 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4396
4397 int32_t points[8] = { xoffset + (sdci[2]/10000), yoffset + (sdci[3]/10000),
4398 xoffset + (sdci[4]/10000), yoffset + (sdci[5]/10000),
4399 xoffset + (sdci[6]/10000), yoffset + (sdci[7]/10000),
4400 xoffset + (sdci[8]/10000), yoffset + (sdci[9]/10000)
4401 };
4402
4403 if(sdci[11]/10000 < 128) //translucent
4404 {
4405 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4406 }
4407
4408 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4409 {
4410 Z_scripterrlog("bitmap->Spline() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4411 return;
4412 }
4413
4414 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4415 if ( refbmp == NULL ) return;
4416
4417 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4418
4419 spline(refbmp, points, sdci[10]/10000);
4420
4421 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4422 }
4423
4424
4425 80910 void bmp_do_putpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4426 {
4427 //sdci[1]=layer
4428 //sdci[2]=x
4429 //sdci[3]=y
4430 //sdci[4]=color
4431 //sdci[5]=rotation anchor x
4432 //sdci[6]=rotation anchor y
4433 //sdci[7]=rotation angle
4434 //sdci[8]=opacity
4435 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4436 80910 int32_t x1=sdci[2]/10000;
4437 80910 int32_t y1=sdci[3]/10000;
4438 80910 int32_t color=sdci[4]/10000;
4439
4440
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if(sdci[8]/10000<=127) //translucent
4441 {
4442 drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0);
4443 }
4444
4445
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4446 {
4447 Z_scripterrlog("bitmap->PutPixel() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4448 return;
4449 }
4450
4451 80910 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4452
1/2
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
80910 if ( refbmp == NULL ) return;
4453
4454
2/4
✓ Branch 0 taken 80910 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 80910 times.
✗ Branch 3 not taken.
80910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4455
4456
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 80910 times.
80910 if(sdci[7]!=0) //rotation
4457 {
4458 int32_t xy[2];
4459 int32_t rx=sdci[5]/10000;
4460 int32_t ry=sdci[6]/10000;
4461 fixed ra1=itofix(sdci[7]%10000)/10000;
4462 fixed ra2=itofix(sdci[7]/10000);
4463 fixed ra=ra1+ra2;
4464
4465 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4466 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4467 x1=xy[0];
4468 y1=xy[1];
4469 }
4470
4471 80910 putpixel(refbmp, x1+xoffset, y1+yoffset, color);
4472 80910 drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0);
4473 80910 }
4474
4475
4476 59816 void bmp_do_drawtiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4477 {
4478 //sdci[1]=layer
4479 //sdci[2]=x
4480 //sdci[3]=y
4481 //sdci[4]=tile
4482 //sdci[5]=tile width
4483 //sdci[6]=tile height
4484 //sdci[7]=color (cset)
4485 //sdci[8]=scale x
4486 //sdci[9]=scale y
4487 //sdci[10]=rotation anchor x
4488 //sdci[11]=rotation anchor y
4489 //sdci[12]=rotation angle
4490 //sdci[13]=flip
4491 //sdci[14]=transparency
4492 //sdci[15]=opacity
4493 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4494
4495 59816 int32_t w = sdci[5]/10000;
4496 59816 int32_t h = sdci[6]/10000;
4497
4498
4/8
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 59816 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 59816 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 59816 times.
59816 if(w < 1 || h < 1 || h > 20 || w > 20)
4499 {
4500 return;
4501 }
4502
4503
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4504 {
4505 Z_scripterrlog("bitmap->DrawTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4506 return;
4507 }
4508
4509 59816 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4510
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 59816 times.
59816 if ( refbmp == NULL ) return;
4511
4512 59816 int32_t xscale=sdci[8]/10000;
4513 59816 int32_t yscale=sdci[9]/10000;
4514 59816 int32_t rx = sdci[10]/10000;
4515 59816 int32_t ry = sdci[11]/10000;
4516 59816 float rotation=sdci[12]/10000;
4517 59816 int32_t flip=(sdci[13]/10000)&3;
4518 59816 bool transparency=sdci[14]!=0;
4519 59816 int32_t opacity=sdci[15]/10000;
4520 59816 int32_t color=sdci[7]/10000;
4521
4522 59816 int32_t x1=sdci[2]/10000;
4523 59816 int32_t y1=sdci[3]/10000;
4524
4525
4526 //don't scale if it's not safe to do so
4527 59816 bool canscale = true;
4528
4529
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if(xscale==0||yscale==0)
4530 {
4531 return;
4532 }
4533
4534
3/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 906 times.
✗ Branch 3 not taken.
59816 if(xscale<0||yscale<0)
4535 58910 canscale = false; //default size
4536
4537
2/4
✓ Branch 0 taken 59816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 59816 times.
59816 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4538
4539
4/4
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 58910 times.
✓ Branch 2 taken 4608 times.
✓ Branch 3 taken 54302 times.
59816 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4540 {
4541 5514 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16);
4542
4543
1/2
✓ Branch 0 taken 5514 times.
✗ Branch 1 not taken.
5514 if(transparency) //transparency
4544 {
4545 5514 TileHelper::OverTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4546 5514 }
4547 else //no transparency
4548 {
4549 TileHelper::OldPutTile(pbitty, (sdci[4]/10000), 0, 0, w, h, color, flip);
4550 }
4551
4552
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 906 times.
5514 if(rotation != 0)
4553 {
4554 //low negative values indicate no anchor-point rotation
4555
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(rx>-777||ry>-777)
4556 {
4557 int32_t xy[2];
4558 4608 fixed ra1=itofix(sdci[12]%10000)/10000;
4559 4608 fixed ra2=itofix(sdci[12]/10000);
4560 4608 fixed ra=ra1+ra2;
4561 4608 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4562 4608 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4563 4608 x1=xy[0];
4564 4608 y1=xy[1];
4565 4608 }
4566
4567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(canscale) //scale first
4568 {
4569 //damnit all, .. fixme.
4570 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4571 clear_bitmap(tempbit);
4572
4573 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4574
4575 if(opacity < 128)
4576 {
4577 clear_bitmap(prim_bmp);
4578 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4579 draw_trans_sprite(bmp, prim_bmp, x1+xoffset, y1+yoffset);
4580 }
4581 else
4582 {
4583 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4584 }
4585
4586 destroy_bitmap(tempbit);
4587 }
4588 else //no scale
4589 {
4590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 if(opacity < 128)
4591 {
4592 clear_bitmap(prim_bmp);
4593 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4594 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4595 }
4596 else
4597 {
4598 4608 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4599 }
4600 }
4601 4608 }
4602 else //scale only
4603 {
4604
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if(canscale)
4605 {
4606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(opacity<128)
4607 {
4608 clear_bitmap(prim_bmp);
4609 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4610 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4611 }
4612 else
4613 {
4614 906 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4615 }
4616 906 }
4617 else //error -do not scale
4618 {
4619 if(opacity<128)
4620 {
4621 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4622 }
4623 else
4624 {
4625 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4626 }
4627 }
4628 }
4629
4630 5514 script_drawing_commands.ReleaseSubBitmap(pbitty);
4631
4632 5514 }
4633 else // no scale or rotation
4634 {
4635
2/2
✓ Branch 0 taken 45964 times.
✓ Branch 1 taken 8338 times.
54302 if(transparency)
4636 {
4637
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45964 times.
45964 if(opacity<=127)
4638 TileHelper::OverTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4639 else
4640 45964 TileHelper::OverTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4641 45964 }
4642 else
4643 {
4644
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8338 times.
8338 if(opacity<=127)
4645 TileHelper::PutTileTranslucent(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip, opacity);
4646 else
4647 8338 TileHelper::OldPutTile(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, color, flip);
4648 }
4649 }
4650 59816 }
4651
4652 void bmp_do_drawtilecloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4653 {
4654 //sdci[1]=layer
4655 //sdci[2]=x
4656 //sdci[3]=y
4657 //sdci[4]=tile
4658 //sdci[5]=tile width
4659 //sdci[6]=tile height
4660 //sdci[7]=flip
4661 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4662
4663 int32_t w = sdci[5]/10000;
4664 int32_t h = sdci[6]/10000;
4665
4666 if(w < 1 || h < 1 || h > 20 || w > 20)
4667 {
4668 return;
4669 }
4670
4671 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4672 {
4673 Z_scripterrlog("bitmap->DrawTileCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4674 return;
4675 }
4676
4677 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4678 if ( refbmp == NULL ) return;
4679
4680 int32_t flip=(sdci[7]/10000)&3;
4681
4682 int32_t x1=sdci[2]/10000;
4683 int32_t y1=sdci[3]/10000;
4684
4685 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4686
4687 TileHelper::OverTileCloaked(refbmp, (sdci[4]/10000), xoffset+x1, yoffset+y1, w, h, flip);
4688 }
4689
4690
4691 824 void bmp_do_drawcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4692 {
4693 //sdci[1]=layer
4694 //sdci[2]=x
4695 //sdci[3]=y
4696 //sdci[4]=combo
4697 //sdci[5]=tile width
4698 //sdci[6]=tile height
4699 //sdci[7]=color (cset)
4700 //sdci[8]=scale x
4701 //sdci[9]=scale y
4702 //sdci[10]=rotation anchor x
4703 //sdci[11]=rotation anchor y
4704 //sdci[12]=rotation angle
4705 //sdci[13]=frame
4706 //sdci[14]=flip
4707 //sdci[15]=transparency
4708 //sdci[16]=opacity
4709 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4710 824 int32_t w = sdci[5]/10000;
4711 824 int32_t h = sdci[6]/10000;
4712
4713
4/8
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 824 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 824 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 824 times.
824 if(w<1||h<1||h>20||w>20)
4714 {
4715 return;
4716 }
4717
4718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4719 {
4720 Z_scripterrlog("bitmap->DrawCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4721 return;
4722 }
4723
4724 824 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4725
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if ( refbmp == NULL ) return;
4726 824 int32_t cmb = (sdci[4]/10000);
4727
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if((unsigned)cmb >= MAXCOMBOS)
4728 {
4729 Z_scripterrlog("DrawCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4730 return;
4731 }
4732
4733 824 int32_t xscale=sdci[8]/10000;
4734 824 int32_t yscale=sdci[9]/10000;
4735 824 int32_t rx = sdci[10]/10000; //these work now
4736 824 int32_t ry = sdci[11]/10000; //these work now
4737 824 float rotation=sdci[12]/10000;
4738
4739 824 bool transparency=sdci[15]!=0;
4740 824 int32_t opacity=sdci[16]/10000;
4741 824 int32_t color=sdci[7]/10000;
4742 824 int32_t x1=sdci[2]/10000;
4743 824 int32_t y1=sdci[3]/10000;
4744
4745 824 const newcombo & c = combobuf[cmb];
4746 824 int32_t tiletodraw = combo_tile(c, x1, y1);
4747 824 int32_t flip = ((sdci[14]/10000) & 3) ^ c.flip;
4748 824 int32_t skiprows=c.skipanimy;
4749
4750
4751 //don't scale if it's not safe to do so
4752 824 bool canscale = true;
4753
4754
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if(xscale==0||yscale==0)
4755 {
4756 return;
4757 }
4758
4759
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
824 if(xscale<0||yscale<0)
4760 824 canscale = false; //default size
4761
4762
2/4
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4763
4764
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 824 times.
824 if((xscale>0 && yscale>0) || rotation) //scaled or rotated
4765 {
4766 BITMAP* pbitty = script_drawing_commands.AquireSubBitmap(w*16, h*16); //-pbitty in the hisouse. :D
4767
4768 if(transparency)
4769 {
4770 TileHelper::OverTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4771 }
4772 else //no transparency
4773 {
4774 TileHelper::OldPutTile(pbitty, tiletodraw, 0, 0, w, h, color, flip, skiprows);
4775 }
4776
4777 if(rotation != 0) // rotate
4778 {
4779 //fixed point sucks ;0
4780 if(rx>-777||ry>-777) //set the rotation anchor and rotate around that
4781 {
4782 int32_t xy[2];
4783 fixed ra1=itofix(sdci[12]%10000)/10000;
4784 fixed ra2=itofix(sdci[12]/10000);
4785 fixed ra=ra1+ra2;
4786 xy[ 0]=rx + fixtoi((fixcos(ra) * (x1 - rx) - fixsin(ra) * (y1 - ry))); //x1
4787 xy[ 1]=ry + fixtoi((fixsin(ra) * (x1 - rx) + fixcos(ra) * (y1 - ry))); //y1
4788 x1=xy[0];
4789 y1=xy[1];
4790 }
4791
4792 if(canscale) //scale first
4793 {
4794 BITMAP* tempbit = create_bitmap_ex(8, xscale>512?512:xscale, yscale>512?512:yscale);
4795 clear_bitmap(tempbit);
4796
4797 stretch_sprite(tempbit, pbitty, 0, 0, xscale, yscale);
4798
4799 if(opacity < 128)
4800 {
4801 clear_bitmap(prim_bmp);
4802 rotate_sprite(prim_bmp, tempbit, 0, 0, degrees_to_fixed(rotation));
4803 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4804 }
4805 else
4806 {
4807 rotate_sprite(refbmp, tempbit, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4808 }
4809
4810 destroy_bitmap(tempbit);
4811 }
4812 else //no scale
4813 {
4814 if(opacity < 128)
4815 {
4816 clear_bitmap(prim_bmp);
4817 rotate_sprite(prim_bmp, pbitty, 0, 0, degrees_to_fixed(rotation));
4818 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4819 }
4820 else
4821 {
4822 rotate_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, degrees_to_fixed(rotation));
4823 }
4824 }
4825 }
4826 else //scale only
4827 {
4828 if(canscale)
4829 {
4830 if(opacity<128)
4831 {
4832 clear_bitmap(prim_bmp);
4833 stretch_sprite(prim_bmp, pbitty, 0, 0, xscale, yscale);
4834 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4835 }
4836 else
4837 {
4838 stretch_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset, xscale, yscale);
4839 }
4840 }
4841 else //error -do not scale
4842 {
4843 if(opacity<128)
4844 {
4845 draw_trans_sprite(refbmp, prim_bmp, x1+xoffset, y1+yoffset);
4846 }
4847 else
4848 {
4849 draw_sprite(refbmp, pbitty, x1+xoffset, y1+yoffset);
4850 }
4851 }
4852 }
4853
4854 script_drawing_commands.ReleaseSubBitmap(pbitty); //rap sucks
4855 }
4856 else // no scale or rotation
4857 {
4858
1/2
✓ Branch 0 taken 824 times.
✗ Branch 1 not taken.
824 if(transparency)
4859 {
4860
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 824 times.
824 if(opacity<=127)
4861 TileHelper::OverTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4862 else
4863 824 TileHelper::OverTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4864 824 }
4865 else
4866 {
4867 if(opacity<=127)
4868 TileHelper::PutTileTranslucent(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, opacity, skiprows);
4869 else
4870 TileHelper::OldPutTile(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, color, flip, skiprows);
4871 }
4872 }
4873 824 }
4874
4875
4876 void bmp_do_drawcombocloakedr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4877 {
4878 //sdci[1]=layer
4879 //sdci[2]=x
4880 //sdci[3]=y
4881 //sdci[4]=combo
4882 //sdci[5]=tile width
4883 //sdci[6]=tile height
4884 //sdci[7]=flip
4885 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4886
4887 int32_t w = sdci[5]/10000;
4888 int32_t h = sdci[6]/10000;
4889
4890 if(w<1||h<1||h>20||w>20)
4891 {
4892 return;
4893 }
4894
4895 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4896 {
4897 Z_scripterrlog("bitmap->DrawComboCloaked() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4898 return;
4899 }
4900
4901 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4902 if ( refbmp == NULL ) return;
4903 int32_t cmb = (sdci[4]/10000);
4904 if((unsigned)cmb >= MAXCOMBOS)
4905 {
4906 Z_scripterrlog("DrawComboCloaked() cannot draw combo '%d', as it is out of bounds.\n", cmb);
4907 return;
4908 }
4909
4910 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4911
4912 int32_t x1=sdci[2]/10000;
4913 int32_t y1=sdci[3]/10000;
4914
4915 const newcombo & c = combobuf[cmb];
4916 int32_t tiletodraw = combo_tile(c, x1, y1);
4917 int32_t flip = ((sdci[7]/10000) & 3) ^ c.flip;
4918 int32_t skiprows=c.skipanimy;
4919
4920 TileHelper::OverTileCloaked(refbmp, tiletodraw, xoffset+x1, yoffset+y1, w, h, flip, skiprows);
4921 }
4922
4923
4924 167483 void bmp_do_fasttiler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4925 {
4926 /* layer, x, y, tile, color opacity */
4927 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4928
4929 167483 int32_t opacity = sdci[6]/10000;
4930
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 167483 times.
167483 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4931 {
4932 Z_scripterrlog("bitmap->FastTile() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4933 return;
4934 }
4935 167483 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4936
1/2
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
167483 if ( refbmp == NULL ) return;
4937
4938
2/4
✓ Branch 0 taken 167483 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 167483 times.
✗ Branch 3 not taken.
167483 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4939
4940
2/2
✓ Branch 0 taken 11131 times.
✓ Branch 1 taken 156352 times.
167483 if(opacity < 128)
4941 11131 overtiletranslucent16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0, opacity);
4942 else
4943 156352 overtile16(refbmp, sdci[4]/10000, xoffset+(sdci[2]/10000), yoffset+(sdci[3]/10000), sdci[5]/10000, 0);
4944 167483 }
4945
4946 19821648 void do_bmpwritetile(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4947 {
4948 /* layer, x, y, tile, is8bit, mask */
4949 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 19821648 times.
19821648 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4951 {
4952 Z_scripterrlog("bitmap->WriteTile() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4953 return;
4954 }
4955 19821648 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4956
1/2
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
19821648 if ( refbmp == NULL ) return;
4957
4958
2/4
✓ Branch 0 taken 19821648 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19821648 times.
✗ Branch 3 not taken.
19821648 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
4959
4960 19821648 int32_t x = (sdci[2]/10000), y = (sdci[3]/10000), tl = (sdci[4]/10000);
4961 19821648 bool is8bit = sdci[5]!=0, mask = sdci[6]!=0;
4962
4963 19821648 write_tile(newtilebuf, refbmp, tl, x+xoffset, y+yoffset, is8bit, mask);
4964 19821648 }
4965
4966 void do_bmpdither(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4967 {
4968 /* layer, mask, color, ditherType, ditherArg */
4969 //sdci[2] Mask Bitmap Pointer
4970 //sdci[3] Color
4971 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
4972 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
4973 {
4974 Z_scripterrlog("bitmap->Dither() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
4975 return;
4976 }
4977 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
4978 if ( refbmp == NULL ) return;
4979 if ( sdci[2] <= 0 )
4980 {
4981 Z_scripterrlog("bitmap->Dither() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
4982 return;
4983 }
4984 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
4985 if ( mask == NULL ) return;
4986
4987 int32_t dType = sdci[4] / 10000L;
4988 if(dType < 0 || dType >= dithMax)
4989 {
4990 Z_scripterrlog("bitmap->Dither() used an invalid dither type: %d. Aborting.\n", dType);
4991 return;
4992 }
4993
4994 ditherblit(refbmp, mask, byte(sdci[3]/10000L), dType, sdci[5]/10000L);
4995 }
4996
4997 6363 void do_bmpreplcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
4998 {
4999 /* layer, shift, startcol, endcol */
5000 //sdci[2] NewCol
5001 //sdci[3] StartCol
5002 //sdci[4] EndCol
5003 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5004
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5005 {
5006 Z_scripterrlog("bitmap->ReplaceColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5007 return;
5008 }
5009 6363 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5010
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6363 times.
6363 if ( refbmp == NULL ) return;
5011 6363 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, false);
5012 6363 }
5013
5014 void do_bmpshiftcol(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5015 {
5016 /* layer, shift, startcol, endcol */
5017 //sdci[2] ShiftAmount
5018 //sdci[3] StartCol
5019 //sdci[4] EndCol
5020 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5021 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5022 {
5023 Z_scripterrlog("bitmap->ShiftColors() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5024 return;
5025 }
5026 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5027 if ( refbmp == NULL ) return;
5028 replColor(refbmp, sdci[2]/10000L, sdci[3]/10000L, sdci[4]/10000L, true);
5029 }
5030
5031 906 void do_bmpmaskdraw(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5032 {
5033 /* layer, mask, color */
5034 //sdci[2] Mask Bitmap Pointer
5035 //sdci[3] Color
5036 //sdci[4] start mask color
5037 //sdci[5] end mask color
5038 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5039 906 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5040
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( refbmp == NULL )
5041 {
5042 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5043 return;
5044 }
5045 906 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5046
1/2
✓ Branch 0 taken 906 times.
✗ Branch 1 not taken.
906 if ( mask == NULL )
5047 {
5048 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[2]);
5049 return;
5050 }
5051 906 auto fillcol = sdci[3]/10000L;
5052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(unsigned(fillcol) > 0xFF) return; //invalid color, nothing to draw
5053 906 auto startcol = vbound(sdci[4]/10000L,0x00,0xFF);
5054 906 auto endcol = vbound(sdci[5]/10000L,0x00,0xFF);
5055 906 mask_colorfill(refbmp, mask, fillcol, startcol, endcol);
5056 906 }
5057
5058 void do_bmpmaskblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5059 {
5060 /* layer, mask, color */
5061 //sdci[2] Mask Bitmap Pointer
5062 //sdci[3] Pattern Bitmap
5063 //sdci[4] bool 'pattern repeats'
5064 //sdci[5] start mask color
5065 //sdci[6] end mask color
5066 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5067 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5068 if ( refbmp == NULL )
5069 {
5070 Z_scripterrlog("bitmap->MaskDraw() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5071 return;
5072 }
5073 BITMAP *mask = FFCore.GetScriptBitmap(sdci[2]);
5074 if ( mask == NULL )
5075 {
5076 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (mask) id: %d. Aborting.\n", sdci[2]);
5077 return;
5078 }
5079 BITMAP *pattern = FFCore.GetScriptBitmap(sdci[3]);
5080 if ( pattern == NULL )
5081 {
5082 Z_scripterrlog("bitmap->MaskDraw() wanted to read from an invalid bitmap (pattern) id: %d. Aborting.\n", sdci[3]);
5083 return;
5084 }
5085 bool repeats = sdci[4]!=0;
5086 auto startcol = vbound(sdci[5]/10000L,0x00,0xFF);
5087 auto endcol = vbound(sdci[6]/10000L,0x00,0xFF);
5088 mask_blit(refbmp, mask, pattern, repeats, startcol, endcol);
5089 }
5090
5091 32636464 void bmp_do_fastcombor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5092 {
5093 /* layer, x, y, tile, color opacity */
5094 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5095 32636464 int32_t opacity = sdci[6] / 10000;
5096 32636464 int32_t x1 = sdci[2] / 10000;
5097 32636464 int32_t y1 = sdci[3] / 10000;
5098 32636464 int32_t index = sdci[4]/10000;
5099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5100 {
5101 Z_scripterrlog("bitmap->FastCombo() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5102 return;
5103 }
5104 32636464 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5105
1/2
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
32636464 if ( refbmp == NULL ) return;
5106 32636464 int32_t cmb = (sdci[4]/10000);
5107
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if((unsigned)cmb >= MAXCOMBOS)
5108 {
5109 Z_scripterrlog("FastCombo() cannot draw combo '%d', as it is out of bounds.\n", cmb);
5110 return;
5111 }
5112
5113
2/4
✓ Branch 0 taken 32636464 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 32636464 times.
✗ Branch 3 not taken.
32636464 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5114
5115 //if( index >= MAXCOMBOS ) return; //bleh.
5116 /*
5117 const newcombo & c = combobuf[index];
5118
5119 if(opacity < 128)
5120 overtiletranslucent16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip, opacity);
5121 else
5122 overtile16(refbmp, combo_tile(c, x1, y1), xoffset+x1, yoffset+y1, sdci[5]/10000, (int32_t)c.flip);
5123 */
5124
5125
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32636464 times.
32636464 if(opacity < 128)
5126 {
5127 overcomboblocktranslucent(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1, 128);
5128
5129 }
5130 else
5131 {
5132 32636464 overcomboblock(refbmp, xoffset+x1, yoffset+y1, cmb, sdci[5]/10000, 1, 1);
5133 }
5134 32636464 }
5135
5136
5137
5138 void bmp_do_drawcharr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5139 {
5140 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5141 {
5142 Z_scripterrlog("bitmap->DrawCharacter() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5143 return;
5144 }
5145 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5146 if ( refbmp == NULL ) return;
5147
5148 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5149
5150 //broken 2.50.2 and earlier drawcharacter()
5151 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5152 {
5153 //sdci[1]=layer
5154 //sdci[2]=x
5155 //sdci[3]=y
5156 //sdci[4]=font
5157 //sdci[5]=color
5158 //sdci[6]=bg color
5159 //sdci[7]=strech x (width)
5160 //sdci[8]=stretch y (height)
5161 //sdci[9]=char
5162 //sdci[10]=opacity
5163 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5164
5165 int32_t x=sdci[2]/10000;
5166 int32_t y=sdci[3]/10000;
5167 int32_t font_index=sdci[4]/10000;
5168 int32_t color=sdci[5]/10000;
5169 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5170 int32_t w=sdci[7]/10000;
5171 int32_t h=sdci[8]/10000;
5172 char glyph=char(sdci[9]/10000);
5173 int32_t opacity=sdci[10]/10000;
5174
5175 //safe check
5176 if(bg_color < -1) bg_color = -1;
5177
5178 if(w>512) w=512; //w=vbound(w,0,512);
5179
5180 if(h>512) h=512; //h=vbound(h,0,512);
5181
5182 //undone
5183 if(w>0&&h>0)//stretch the character
5184 {
5185 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5186
5187 if(opacity < 128)
5188 {
5189 if(w>128||h>128)
5190 {
5191 clear_bitmap(prim_bmp);
5192
5193 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5194 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5195 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5196 }
5197 else //this is faster
5198 {
5199 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5200
5201 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5202 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5203 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5204
5205 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5206 }
5207 }
5208 else // no opacity
5209 {
5210 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5211 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5212 }
5213
5214 }
5215 else //no stretch
5216 {
5217 if(opacity < 128)
5218 {
5219 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5220 clear_bitmap(pbmp);
5221
5222 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5223 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5224
5225 destroy_bitmap(pbmp);
5226 }
5227 else // no opacity
5228 {
5229 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5230 }
5231 }
5232 }
5233
5234 else //2.53.0 fixed version and later.
5235 {
5236
5237 //sdci[1]=layer
5238 //sdci[2]=x
5239 //sdci[3]=y
5240 //sdci[4]=font
5241 //sdci[5]=color
5242 //sdci[6]=bg color
5243 //sdci[7]=strech x (width)
5244 //sdci[8]=stretch y (height)
5245 //sdci[9]=char
5246 //sdci[10]=opacity
5247
5248 int32_t x=sdci[2]/10000;
5249 int32_t y=sdci[3]/10000;
5250 int32_t font_index=sdci[4]/10000;
5251 int32_t color=sdci[5]/10000;
5252 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5253 int32_t w=sdci[7]/10000;
5254 int32_t h=sdci[8]/10000;
5255 char glyph=char(sdci[9]/10000);
5256 int32_t opacity=sdci[10]/10000;
5257
5258 //safe check
5259 if(bg_color < -1) bg_color = -1;
5260
5261 if(w>512) w=512; //w=vbound(w,0,512);
5262
5263 if(h>512) h=512; //h=vbound(h,0,512);
5264
5265 //undone
5266 if(w>0&&h>0)//stretch the character
5267 {
5268 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5269
5270 if(opacity < 128)
5271 {
5272 if(w>128||h>128)
5273 {
5274 clear_bitmap(prim_bmp);
5275
5276 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5277 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5278 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5279 }
5280 else //this is faster
5281 {
5282 BITMAP *pbmp2 = script_drawing_commands.AquireSubBitmap(w,h);
5283
5284 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5285 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5286 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5287
5288 script_drawing_commands.ReleaseSubBitmap(pbmp2);
5289 }
5290 }
5291 else // no opacity
5292 {
5293 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5294 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5295 }
5296
5297 }
5298 else //no stretch
5299 {
5300 if(opacity < 128)
5301 {
5302 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5303 clear_bitmap(pbmp);
5304
5305 textprintf_ex(pbmp, get_zc_font(font_index), 0, 0, color, bg_color, "%c", glyph);
5306 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5307
5308 destroy_bitmap(pbmp);
5309 }
5310 else // no opacity
5311 {
5312 textprintf_ex(refbmp, get_zc_font(font_index), x+xoffset, y+yoffset, color, bg_color, "%c", glyph);
5313 }
5314 }
5315
5316 }
5317
5318 }
5319
5320
5321 void bmp_do_drawintr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5322 {
5323 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5324 {
5325 Z_scripterrlog("bitmap->DrawInteger() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5326 return;
5327 }
5328 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5329 if ( refbmp == NULL ) return;
5330
5331 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5332
5333 //broken 2.50.2 and earlier drawinteger()
5334 if ( get_qr(qr_BROKENCHARINTDRAWING) )
5335 {
5336 //sdci[1]=layer
5337 //sdci[2]=x
5338 //sdci[3]=y
5339 //sdci[4]=font
5340 //sdci[5]=color
5341 //sdci[6]=bg color
5342 //sdci[7]=strech x (width)
5343 //sdci[8]=stretch y (height)
5344 //sdci[9]=integer
5345 //sdci[10]=num decimal places
5346 //sdci[11]=opacity
5347 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5348
5349 int32_t x=sdci[2]/10000;
5350 int32_t y=sdci[3]/10000;
5351 int32_t font_index=sdci[4]/10000;
5352 int32_t color=sdci[5]/10000;
5353 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5354 int32_t w=sdci[7]/10000;
5355 int32_t h=sdci[8]/10000;
5356 int32_t decplace=sdci[10]/10000;
5357 int32_t opacity=sdci[11]/10000;
5358
5359 //safe check
5360 if(bg_color < -1) bg_color = -1;
5361
5362 if(w>512) w=512; //w=vbound(w,0,512);
5363
5364 if(h>512) h=512; //h=vbound(h,0,512);
5365
5366 char numbuf[15];
5367
5368 switch(decplace)
5369 {
5370 default:
5371 case 0:
5372 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5373 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5374
5375 case 1:
5376 //sprintf(numbuf,"%.01f",number);
5377 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5378 break;
5379
5380 case 2:
5381 //sprintf(numbuf,"%.02f",number);
5382 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5383 break;
5384
5385 case 3:
5386 //sprintf(numbuf,"%.03f",number);
5387 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5388 break;
5389
5390 case 4:
5391 //sprintf(numbuf,"%.04f",number);
5392 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5393 break;
5394 }
5395
5396 if(w>0&&h>0)//stretch
5397 {
5398 BITMAP *pbmp = script_drawing_commands.GetSmallTextureBitmap(1,1);
5399
5400 if(opacity < 128)
5401 {
5402 if(w>128||h>128)
5403 {
5404 clear_bitmap(prim_bmp);
5405
5406 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5407 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5408 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5409 }
5410 else
5411 {
5412 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5413 clear_bitmap(pbmp2);
5414
5415 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5416 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5417 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5418
5419 destroy_bitmap(pbmp2);
5420 }
5421 }
5422 else // no opacity
5423 {
5424 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5425 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5426 }
5427
5428 }
5429 else //no stretch
5430 {
5431 if(opacity < 128)
5432 {
5433 BITMAP *pbmp = create_sub_bitmap(prim_bmp,0,0,16,16);
5434 clear_bitmap(pbmp);
5435
5436 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5437 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5438
5439 destroy_bitmap(pbmp);
5440 }
5441 else // no opacity
5442 {
5443 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5444 }
5445 }
5446
5447 }
5448
5449 else //2.53.0 fixed version and later.
5450 {
5451 //sdci[1]=layer
5452 //sdci[2]=x
5453 //sdci[3]=y
5454 //sdci[4]=font
5455 //sdci[5]=color
5456 //sdci[6]=bg color
5457 //sdci[7]=strech x (width)
5458 //sdci[8]=stretch y (height)
5459 //sdci[9]=integer
5460 //sdci[10]=num decimal places
5461 //sdci[11]=opacity
5462
5463 int32_t x=sdci[2]/10000;
5464 int32_t y=sdci[3]/10000;
5465 int32_t font_index=sdci[4]/10000;
5466 int32_t color=sdci[5]/10000;
5467 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5468 int32_t w=sdci[7]/10000;
5469 int32_t h=sdci[8]/10000;
5470 int32_t decplace=sdci[10]/10000;
5471 int32_t opacity=sdci[11]/10000;
5472
5473 //safe check
5474 if(bg_color < -1) bg_color = -1;
5475
5476 if(w>512) w=512; //w=vbound(w,0,512);
5477
5478 if(h>512) h=512; //h=vbound(h,0,512);
5479
5480 char numbuf[15];
5481
5482 switch(decplace)
5483 {
5484 default:
5485 case 0:
5486 sprintf(numbuf,"%d",(sdci[9]/10000)); //For some reason, static casting for zero decimal places was
5487 break; //reducing the value by -1, so 8.000 printed as '7'. -Z
5488
5489 case 1:
5490 //sprintf(numbuf,"%.01f",number);
5491 sprintf(numbuf,"%.01f",(static_cast<float>(sdci[9])/10000.0f)); //Would this be slower?
5492 break;
5493
5494 case 2:
5495 //sprintf(numbuf,"%.02f",number);
5496 sprintf(numbuf,"%.02f",(static_cast<float>(sdci[9])/10000.0f));
5497 break;
5498
5499 case 3:
5500 //sprintf(numbuf,"%.03f",number);
5501 sprintf(numbuf,"%.03f",(static_cast<float>(sdci[9])/10000.0f));
5502 break;
5503
5504 case 4:
5505 //sprintf(numbuf,"%.04f",number);
5506 sprintf(numbuf,"%.04f",(static_cast<float>(sdci[9])/10000.0f));
5507 break;
5508 }
5509
5510 //FONT* font=get_zc_font(sdci[4]/10000);
5511
5512 if(w>0&&h>0)//stretch
5513 {
5514 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(get_zc_font(font_index), numbuf)+1, text_height(get_zc_font(font_index)));
5515 clear_bitmap(pbmp);
5516 //script_drawing_commands.GetSmallTextureBitmap(1,1);
5517
5518 if(opacity < 128)
5519 {
5520 if(w>128||h>128)
5521 {
5522 clear_bitmap(prim_bmp);
5523
5524 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5525 stretch_sprite(prim_bmp, pbmp, 0, 0, w, h);
5526 draw_trans_sprite(refbmp, prim_bmp, x+xoffset, y+yoffset);
5527 }
5528 else
5529 {
5530 BITMAP *pbmp2 = create_sub_bitmap(prim_bmp,0,0,w,h);
5531 clear_bitmap(pbmp2);
5532
5533 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5534 stretch_sprite(pbmp2, pbmp, 0, 0, w, h);
5535 draw_trans_sprite(refbmp, pbmp2, x+xoffset, y+yoffset);
5536
5537 destroy_bitmap(pbmp2);
5538 }
5539 }
5540 else // no opacity
5541 {
5542 textout_ex(pbmp, get_zc_font(font_index), numbuf, 0, 0, color, bg_color);
5543 stretch_sprite(refbmp, pbmp, x+xoffset, y+yoffset, w, h);
5544 }
5545
5546 }
5547 else //no stretch
5548 {
5549 if(opacity < 128)
5550 {
5551 FONT* font = get_zc_font(font_index);
5552 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, text_length(font, numbuf), text_height(font));
5553 clear_bitmap(pbmp);
5554
5555 textout_ex(pbmp, font, numbuf, 0, 0, color, bg_color);
5556 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5557
5558 destroy_bitmap(pbmp);
5559 }
5560 else // no opacity
5561 {
5562 textout_ex(refbmp, get_zc_font(font_index), numbuf, x+xoffset, y+yoffset, color, bg_color);
5563 }
5564 }
5565 }
5566 }
5567
5568
5569 855 void bmp_do_drawstringr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5570 {
5571 //sdci[1]=layer
5572 //sdci[2]=x
5573 //sdci[3]=y
5574 //sdci[4]=font
5575 //sdci[5]=color
5576 //sdci[6]=bg color
5577 //sdci[7]=format_option
5578 //sdci[8]=string
5579 //sdci[9]=opacity
5580 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5581
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5582 {
5583 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5584 return;
5585 }
5586
5587 855 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5588
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if ( refbmp == NULL ) return;
5589
5590
2/4
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 855 times.
855 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5591
5592 855 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5593
5594
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if(!str)
5595 {
5596 al_trace("String pointer is null! Internal error. \n");
5597 return;
5598 }
5599
5600 855 int32_t x=sdci[2]/10000;
5601 855 int32_t y=sdci[3]/10000;
5602 855 FONT* font=get_zc_font(sdci[4]/10000);
5603 855 int32_t color=sdci[5]/10000;
5604 855 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5605 855 int32_t format_type=sdci[7]/10000;
5606 855 int32_t opacity=sdci[9]/10000;
5607 //sdci[8] not needed :)
5608
5609 //safe check
5610
1/2
✓ Branch 0 taken 855 times.
✗ Branch 1 not taken.
855 if(bg_color < -1) bg_color = -1;
5611
5612
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if(opacity < 128)
5613 {
5614 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5615 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5616 clear_bitmap(pbmp);
5617 textout_ex(pbmp, font, str->c_str(), 0, 0, color, bg_color);
5618 if(format_type == 2) // right-sided text
5619 x-=width;
5620 else if(format_type == 1) // centered text
5621 x-=width/2;
5622 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5623 destroy_bitmap(pbmp);
5624 }
5625 else // no opacity
5626 {
5627
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 if(format_type == 2) // right-sided text
5628 {
5629 textout_right_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5630 }
5631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 855 times.
855 else if(format_type == 1) // centered text
5632 {
5633 textout_centre_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5634 }
5635 else // standard left-sided text
5636 {
5637 855 textout_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, color, bg_color);
5638 }
5639 }
5640 855 }
5641
5642 45504 void bmp_do_drawstringr2(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5643 {
5644 //sdci[1]=layer
5645 //sdci[2]=x
5646 //sdci[3]=y
5647 //sdci[4]=font
5648 //sdci[5]=color
5649 //sdci[6]=bg color
5650 //sdci[7]=format_option
5651 //sdci[8]=string
5652 //sdci[9]=opacity
5653 //sdci[10]=shadowtype
5654 //sdci[11]=shadow_color
5655 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5656
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5657 {
5658 Z_scripterrlog("bitmap->DrawString() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5659 return;
5660 }
5661
5662 45504 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5663
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if ( refbmp == NULL ) return;
5664
5665
2/4
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45504 times.
45504 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5666
5667 45504 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5668
5669
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(!str)
5670 {
5671 al_trace("String pointer is null! Internal error. \n");
5672 return;
5673 }
5674
5675 45504 int32_t x=sdci[2]/10000;
5676 45504 int32_t y=sdci[3]/10000;
5677 45504 FONT* font=get_zc_font(sdci[4]/10000);
5678 45504 int32_t color=sdci[5]/10000;
5679 45504 int32_t bg_color=sdci[6]/10000; //-1 = transparent
5680 45504 int32_t format_type=sdci[7]/10000;
5681 45504 int32_t opacity=sdci[9]/10000;
5682 45504 int32_t textstyle = sdci[10]/10000;
5683 45504 int32_t shadow_color = sdci[11]/10000;
5684 //sdci[8] not needed :)
5685
5686 //safe check
5687
1/2
✓ Branch 0 taken 45504 times.
✗ Branch 1 not taken.
45504 if(bg_color < -1) bg_color = -1;
5688
5689
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 45504 times.
45504 if(opacity < 128)
5690 {
5691 int32_t width=zc_min(text_length(font, str->c_str()), 512);
5692 BITMAP *pbmp = create_sub_bitmap(prim_bmp, 0, 0, width, text_height(font));
5693 clear_bitmap(pbmp);
5694 textout_styled_aligned_ex(pbmp, font, str->c_str(), 0, 0, textstyle, sstaLEFT, color, shadow_color, bg_color);
5695 if(format_type == 2) // right-sided text
5696 x-=width;
5697 else if(format_type == 1) // centered text
5698 x-=width/2;
5699 draw_trans_sprite(refbmp, pbmp, x+xoffset, y+yoffset);
5700 destroy_bitmap(pbmp);
5701 }
5702 else // no opacity
5703 {
5704 45504 textout_styled_aligned_ex(refbmp, font, str->c_str(), x+xoffset, y+yoffset, textstyle, format_type, color, shadow_color, bg_color);
5705 }
5706 45504 }
5707
5708 324163 void bmp_do_clearr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5709 {
5710
1/2
✓ Branch 0 taken 324163 times.
✗ Branch 1 not taken.
324163 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5711 {
5712 Z_scripterrlog("bitmap->Clear() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5713 return;
5714 }
5715 324163 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5716 324163 auto& usr_bitmap = scb.get(bitid);
5717
1/2
✓ Branch 0 taken 324163 times.
✗ Branch 1 not taken.
324163 if (usr_bitmap.u_bmp)
5718 324163 clear_bitmap(usr_bitmap.u_bmp);
5719 324163 }
5720
5721 2790 void bmp_do_clearcolorr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5722 {
5723 //sdci[1]=layer
5724 //sdci[2]=color
5725 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5726 2790 int32_t pal_color = sdci[2]/10000;
5727
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5728 {
5729 Z_scripterrlog("bitmap->ClearToColor() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5730 return;
5731 }
5732 2790 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5733 2790 auto& usr_bitmap = scb.get(bitid);
5734
1/2
✓ Branch 0 taken 2790 times.
✗ Branch 1 not taken.
2790 if (usr_bitmap.u_bmp)
5735 2790 clear_to_color(usr_bitmap.u_bmp, pal_color);
5736 2790 }
5737
5738
5739 34653 void bmp_do_regenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5740 {
5741 //sdci[1]=layer
5742 34653 int32_t h = sdci[3]/10000;
5743 34653 int32_t w = sdci[2]/10000;
5744
1/2
✓ Branch 0 taken 34653 times.
✗ Branch 1 not taken.
34653 if ( get_qr(qr_OLDCREATEBITMAP_ARGS) )
5745 {
5746 //flip height and width
5747 h = h ^ w;
5748 w = h ^ w;
5749 h = h ^ w;
5750 }
5751 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5752 //Z_scripterrlog("bitmap->Create() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5753
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 34653 times.
34653 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5754 {
5755 Z_scripterrlog("bitmap->Create() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5756 return;
5757 }
5758 34653 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5759 34653 auto& usr_bmp = scb.get(bitid);
5760
2/2
✓ Branch 0 taken 34528 times.
✓ Branch 1 taken 125 times.
34653 if ( usr_bmp.u_bmp )
5761 34528 destroy_bitmap(usr_bmp.u_bmp);
5762 34653 usr_bmp.u_bmp = create_bitmap_ex(8,w,h);
5763
5764 34653 usr_bmp.width = w;
5765 34653 usr_bmp.height = h;
5766 34653 }
5767
5768 void bmp_do_readr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5769 {
5770 //sdci[1]=layer
5771 //sdci[2]=filename
5772 //sdci[3]=y
5773 //sdci[4]=font
5774 //sdci[5]=color
5775 //sdci[6]=bg color
5776 //sdci[7]=format_option
5777 //sdci[8]=string
5778 //sdci[9]=opacity
5779 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5780 //Z_scripterrlog("bitmap->Read() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5781 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5782 {
5783 Z_scripterrlog("bitmap->Read() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5784 return;
5785 }
5786 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5787 auto& usr_bitmap = scb.get(bitid);
5788 usr_bitmap.destroy();
5789
5790 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5791
5792 if(!str)
5793 {
5794 al_trace("String pointer is null! Internal error. \n");
5795 return;
5796 }
5797
5798 PALETTE tempPal;
5799 get_palette(tempPal);
5800 if ( checkPath(str->c_str(), false) )
5801 {
5802 usr_bitmap.u_bmp = load_bitmap(str->c_str(), tempPal);
5803 usr_bitmap.width = usr_bitmap.u_bmp->w;
5804 usr_bitmap.height = usr_bitmap.u_bmp->h;
5805 if ( !usr_bitmap.u_bmp )
5806 {
5807 Z_scripterrlog("Failed to load image file %s.\nMaking a blank bitmap on the pointer.\n", str->c_str());
5808 }
5809 else
5810 {
5811 zprint("Read image file %s\n",str->c_str());
5812 }
5813 }
5814 else
5815 {
5816 Z_scripterrlog("Failed to load image file: %s. File not found. Creating a blank bitmap on the pointer.\n", str->c_str());
5817 usr_bitmap.u_bmp = create_bitmap_ex(8,256,176);
5818 clear_bitmap(usr_bitmap.u_bmp);
5819 }
5820 }
5821
5822
5823
5824 void bmp_do_writer(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5825 {
5826 //sdci[1]=layer
5827 //sdci[2]=filename
5828 //sdci[3]=y
5829 //sdci[4]=font
5830 //sdci[5]=color
5831 //sdci[6]=bg color
5832 //sdci[7]=format_option
5833 //sdci[8]=string
5834 //sdci[9]=opacity
5835 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5836 //Z_scripterrlog("bitmap->Write() pointer is: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5837
5838 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5839 {
5840 Z_scripterrlog("bitmap->Write() wanted to use to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5841 return;
5842 }
5843 int32_t bitid = sdci[DRAWCMD_BMP_TARGET];
5844 auto& usr_bitmap = scb.get(bitid);
5845 if (!usr_bitmap.u_bmp)
5846 {
5847 Z_scripterrlog("Tried to write from an invalid bitmap pointer %d. Aborting. \n", sdci[DRAWCMD_BMP_TARGET]);
5848 return;
5849 }
5850
5851 bool overwrite = (sdci[3] != 0);
5852 std::string* str = (std::string*)script_drawing_commands[i].GetPtr();
5853
5854 if(!str)
5855 {
5856 al_trace("String pointer is null! Internal error. \n");
5857 return;
5858 }
5859
5860 //char *cptr = new char[str->size()+1]; // +1 to account for \0 byte
5861 //std::strncpy(cptr, str->c_str(), str->size());
5862 //Z_scripterrlog("bitmap->Write extension matches ? : %s\n!", (FFCore.checkExtension(str->c_str(), ".png")) ? "true" : "false");
5863 //Z_scripterrlog("Trying to write filename %s\n", cptr);
5864 if
5865 (
5866 ( (FFCore.checkExtension(*str, "")) ) ||
5867 ( !(FFCore.checkExtension(*str, ".png")) && !(FFCore.checkExtension(*str, ".gif")) && !(FFCore.checkExtension(*str, ".bmp"))
5868 && !(FFCore.checkExtension(*str, ".pcx")) && !(FFCore.checkExtension(*str, ".tga")) )
5869 )
5870 {
5871 Z_scripterrlog("No extension, or invalid extension provided for writing bitmap file %s. Could not write the file.\nValid types are .png, .gif, .pcx, .tgx, and .bmp. Aborting.\n",str->c_str());
5872 }
5873 else if ( overwrite || (!checkPath(str->c_str(), false)) )
5874 {
5875 if(make_dirs_for_file(*str))
5876 {
5877 save_bitmap(str->c_str(), usr_bitmap.u_bmp, RAMpal);
5878 if(checkPath(str->c_str(), false))
5879 {
5880 zprint("Wrote image file %s\n",str->c_str());
5881 }
5882 else
5883 {
5884 Z_scripterrlog("Failed to create file '%s'\n",str->c_str());
5885 }
5886 }
5887 else
5888 {
5889 Z_scripterrlog("Cannot write file '%s' because the directory does not exist, and could not be created.\n", str->c_str());
5890 }
5891 }
5892 else Z_scripterrlog("Cannot write file '%s' because the file already exists in the specified path.\n", str->c_str());
5893 }
5894
5895
5896 void bmp_do_drawquadr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
5897 {
5898 //sdci[1]=layer
5899 //sdci[2]=x1
5900 //sdci[3]=y1
5901 //sdci[4]=x2
5902 //sdci[5]=y2
5903 //sdci[6]=x3
5904 //sdci[7]=y3
5905 //sdci[8]=x4
5906 //sdci[9]=y4
5907 //sdci[10]=width
5908 //sdci[11]=height
5909 //sdci[12]=cset
5910 //sdci[13]=flip
5911 //sdci[14]=tile/combo
5912 //sdci[15]=polytype
5913 //sdci[16] = other bitmap as texture
5914 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
5915 Z_scripterrlog("bitmap quad pointer: %d\n", sdci[DRAWCMD_BMP_TARGET]);
5916 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
5917 {
5918 Z_scripterrlog("bitmap->Quad() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
5919 return;
5920 }
5921 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
5922
5923 if ( !refbmp ) return;
5924
5925 int32_t x1 = sdci[2]/10000;
5926 int32_t y1 = sdci[3]/10000;
5927 int32_t x2 = sdci[4]/10000;
5928 int32_t y2 = sdci[5]/10000;
5929 int32_t x3 = sdci[6]/10000;
5930 int32_t y3 = sdci[7]/10000;
5931 int32_t x4 = sdci[8]/10000;
5932 int32_t y4 = sdci[9]/10000;
5933 int32_t w = sdci[10]/10000;
5934 int32_t h = sdci[11]/10000;
5935 int32_t color = sdci[12]/10000;
5936 int32_t flip=(sdci[13]/10000)&3;
5937 int32_t tile = sdci[14]/10000;
5938 int32_t polytype = sdci[15]/10000;
5939 int32_t quad_render_source = sdci[16];
5940 //Z_scripterrlog("bitmap->Quad() render source is: %d\n", quad_render_source);
5941
5942 bool tex_is_bitmap = ( sdci[16] != 0 );
5943
5944 BITMAP *bmptexture=NULL;
5945 BITMAP *tex=NULL;
5946 polytype = vbound(polytype, 0, 14);
5947
5948 int32_t col[4];
5949 col[0]=col[1]=col[2]=col[3]=color;
5950 bool mustDestroyBmp = false;
5951
5952 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
5953
5954 if ( tex_is_bitmap )
5955 {
5956 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
5957 if ( !bmptexture )
5958 {
5959 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
5960 tex_is_bitmap = 0;
5961 }
5962 }
5963
5964 if ( tex_is_bitmap )
5965 {
5966
5967 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5968 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
5969 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", w);
5970 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad is not a POWER OF TWO.\nTextels may render improperly!\n", h);
5971
5972 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
5973 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
5974 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
5975 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
5976
5977 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
5978 }
5979 else
5980 {
5981 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
5982 if(!tex)
5983 {
5984 //Z_scripterrlog("Bitmap->Quad() found an invalid texture bitmap.\n");
5985 mustDestroyBmp = true;
5986 tex = create_bitmap_ex(8, w*16, h*16);
5987 clear_bitmap(tex);
5988 }
5989
5990 if(tile > 0) // TILE
5991 {
5992 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
5993 }
5994
5995 if ( tile < 0 ) // COMBO
5996 {
5997 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
5998 const int32_t tiletodraw = combo_tile(c, x1, y1);
5999 flip = flip ^ c.flip;
6000
6001 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6002 }
6003 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6004 {
6005 Z_message("Quad() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6006 return; //non power of two error
6007 }
6008 //Z_scripterrlog("bitmap->Quad() is trying to blit from a bitmap texture.\n");
6009 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6010 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(h), col[1] };
6011 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(w), static_cast<float>(h), col[2] };
6012 V3D_f V4 = { static_cast<float>(x4+xoffset), static_cast<float>(y4+yoffset), 0, static_cast<float>(w), 0, col[3] };
6013
6014 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
6015
6016 }
6017
6018
6019
6020
6021 //todo: finish palette shading
6022 /*
6023 POLYTYPE_FLAT
6024 POLYTYPE_GCOL
6025 POLYTYPE_GRGB
6026 POLYTYPE_ATEX
6027 POLYTYPE_PTEX
6028 POLYTYPE_ATEX_MASK
6029 POLYTYPE_PTEX_MASK
6030 POLYTYPE_ATEX_LIT
6031 POLYTYPE_PTEX_LIT
6032 POLYTYPE_ATEX_MASK_LIT
6033 POLYTYPE_PTEX_MASK_LIT
6034 POLYTYPE_ATEX_TRANS
6035 POLYTYPE_PTEX_TRANS
6036 POLYTYPE_ATEX_MASK_TRANS
6037 POLYTYPE_PTEX_MASK_TRANS
6038 */
6039
6040 if(mustDestroyBmp)
6041 destroy_bitmap(tex);
6042
6043 }
6044
6045
6046 void bmp_do_getpixelr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6047 {
6048 //sdci[1]=layer
6049 //sdci[2]=x1
6050 //sdci[3]=y1
6051
6052 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6053 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6054 {
6055 Z_scripterrlog("bitmap->GetPixel() wanted to read from an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6056 return;
6057 }
6058 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6059 if ( refbmp == NULL ) return;
6060
6061
6062 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6063
6064 int32_t x1 = sdci[2]/10000;
6065 int32_t y1 = (sdci[3]/10000)+yoffset;
6066 int32_t col = getpixel(scb.get(sdci[DRAWCMD_BMP_TARGET]).u_bmp, x1, y1);
6067 Z_scripterrlog("bitmap->GetPixel col is %d\n",col);
6068 Z_scripterrlog("bitmap->GetPixel bitmap ptr is is %d\n",(sdci[DRAWCMD_BMP_TARGET]));
6069 FFCore.set_sarg1(col);
6070 }
6071
6072
6073
6074
6075 void bmp_do_drawtriangler(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6076 {
6077 //sdci[1]=layer
6078 //sdci[2]=x1
6079 //sdci[3]=y1
6080 //sdci[4]=x2
6081 //sdci[5]=y2
6082 //sdci[6]=x3
6083 //sdci[7]=y3
6084 //sdci[8]=width
6085 //sdci[9]=height
6086 //sdci[10]=cset
6087 //sdci[11]=flip
6088 //sdci[12]=tile/combo
6089 //sdci[13]=polytype
6090 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6091 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
6092 {
6093 Z_scripterrlog("bitmap->Triangle() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
6094 return;
6095 }
6096 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
6097 if ( refbmp == NULL ) return;
6098
6099
6100 int32_t render_source = sdci[14];
6101 //Z_scripterrlog("bitmap->Triangle() render source is: %d\n", render_source);
6102
6103 bool tex_is_bitmap = ( sdci[14] != 0 );
6104
6105 BITMAP *bmptexture=NULL;
6106 if ( tex_is_bitmap )
6107 {
6108 bmptexture = FFCore.GetScriptBitmap(render_source);
6109 if ( !bmptexture )
6110 {
6111 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
6112 tex_is_bitmap = 0;
6113 }
6114 }
6115
6116 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6117
6118 int32_t x1 = sdci[2]/10000;
6119 int32_t y1 = sdci[3]/10000;
6120 int32_t x2 = sdci[4]/10000;
6121 int32_t y2 = sdci[5]/10000;
6122 int32_t x3 = sdci[6]/10000;
6123 int32_t y3 = sdci[7]/10000;
6124 int32_t w = sdci[8]/10000;
6125 int32_t h = sdci[9]/10000;
6126 int32_t color = sdci[10]/10000;
6127 int32_t flip=(sdci[11]/10000)&3;
6128 int32_t tile = sdci[12]/10000;
6129 int32_t polytype = sdci[13]/10000;
6130
6131 polytype = vbound(polytype, 0, 14);
6132 int32_t utex_w = w;
6133 int32_t utex_h = h;
6134
6135
6136 int32_t tex_width = w*16;
6137 int32_t tex_height = h*16;
6138
6139 bool mustDestroyBmp = false;
6140 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
6141
6142 if(!tex)
6143 {
6144 mustDestroyBmp = true;
6145 tex = create_bitmap_ex(8, tex_width, tex_height);
6146 clear_bitmap(tex);
6147 }
6148
6149 int32_t col[3];
6150 /*
6151 if( color < 0 )
6152 {
6153 col[0]=draw_container.color_buffer[0];
6154 col[1]=draw_container.color_buffer[1];
6155 col[2]=draw_container.color_buffer[2];
6156 }
6157 else */
6158 {
6159 col[0]=col[1]=col[2]=color;
6160 }
6161
6162 if(tile > 0) // TILE
6163 {
6164 TileHelper::OverTile(tex, tile, 0, 0, w, h, color, flip);
6165 }
6166 else // COMBO
6167 {
6168 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
6169 const int32_t tiletodraw = combo_tile(c, x1, y1);
6170 flip = flip ^ c.flip;
6171
6172 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, color, flip);
6173 }
6174 if ( !tex_is_bitmap )
6175 {
6176 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
6177 {
6178 Z_message("bitmap->Triangle() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
6179 return; //non power of two error
6180 }
6181 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6182 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(tex_height), col[1] };
6183 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(tex_width), static_cast<float>(tex_height), col[2] };
6184
6185
6186 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
6187
6188 }
6189
6190 else
6191 {
6192 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6193 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", render_source);
6194 if ( !isPowerOfTwo(utex_h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_w);
6195 if ( !isPowerOfTwo(utex_w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle is not a POWER OF TWO.\nTextels may render improperly!\n", utex_h);
6196
6197 V3D_f V1 = { static_cast<float>(x1+xoffset), static_cast<float>(y1+yoffset), 0, 0, 0, col[0] };
6198 V3D_f V2 = { static_cast<float>(x2+xoffset), static_cast<float>(y2+yoffset), 0, 0, static_cast<float>(utex_h), col[1] };
6199 V3D_f V3 = { static_cast<float>(x3+xoffset), static_cast<float>(y3+yoffset), 0, static_cast<float>(utex_w), static_cast<float>(utex_h), col[2] };
6200
6201
6202 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
6203
6204 }
6205
6206 if(mustDestroyBmp)
6207 destroy_bitmap(tex);
6208 }
6209
6210
6211 void bmp_do_mode7r(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6212 {
6213 /*
6214 int32_t layer, int32_t rt, int32_t srcX, int32_t srcY, int32_t srcW, int32_t srcH, int32_t destW, int32_t destH, int32_t angle, int32_t cx, int32_t cy, int32_t space_z, int32_t horizon,
6215 int32_t scale_x, int32_t scale_y){
6216
6217 //sdci[1]=layer
6218 //sdci[2]=bitmap target
6219 //
6220 // -2 is the current Render Target
6221 // -1, this is the screen (framebuf).
6222 // 0: Render target 0
6223 // 1: Render target 1
6224 // 2: Render target 2
6225 // 3: Render target 3
6226 // 4: Render target 4
6227 // 5: Render target 5
6228 // 6: Render target 6
6229 // Otherwise: The pointer to a bitmap.
6230
6231 //sdci[3]=sourcex
6232 //sdci[4]=sourcey
6233 //sdci[5]=sourcew
6234 //sdci[6]=sourceh
6235
6236 //sdci[7]=destw
6237 //sdci[8]=desth
6238 //sdci[9]=angle
6239 //scdi[10] = pivot cx
6240 //sdci[11] = pivot cy
6241 //sdci[12] = space Z
6242 //sdci[13] = horizon
6243 //scdi[14] = scale X
6244 //scdi[15] = scale Y
6245 //sdci[16] = masked?
6246 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6247
6248
6249
6250 // ZScript-side constant values:
6251 const int32_t BITDX_NORMAL = 0;
6252 const int32_t BITDX_TRANS = 1; //Translucent
6253 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6254 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6255 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6256 //Note: Some modes cannot be combined. if a combination is not supported, an error
6257 // detailing this will be shown in allegro.log.
6258
6259 //scdi[15] = litcolour
6260 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6261 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6262
6263 //sdci[16]=mask
6264
6265 */
6266
6267
6268 int32_t bitmapIndex = sdci[2];
6269 int32_t usr_bitmap_index = sdci[2];
6270 //Z_scripterrlog("bitmap index is: %d\n",bitmapIndex);
6271 //Z_scripterrlog("DrawPlane() bitmapIndex is: %d\n", bitmapIndex);
6272
6273 if ( bitmapIndex >= 10000 )
6274 {
6275 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6276 }
6277 else if ( usr_bitmap_index > 0 )
6278 {
6279 bitmapIndex = usr_bitmap_index;
6280 // Z_scripterrlog("Mode7 is using a user bitmap target, pointer: %d\n", usr_bitmap_index);
6281 yoffset = 0;
6282 }
6283
6284 //rendering mode 7 args
6285 double srcX = sdci[3]/10000.0;
6286 double srcY = sdci[4]/10000.0;
6287 double destX = sdci[5]/10000.0;
6288 double destY = sdci[6]/10000.0;
6289
6290 double destW = sdci[7]/10000.0;
6291 double destH = sdci[8]/10000.0;
6292 double space_z = sdci[9]/10000.0;
6293 double horizon = sdci[10]/10000.0;
6294 double scale_x = sdci[11]/10000.0;
6295 double scale_y = sdci[12]/10000.0;
6296 byte masked = ( sdci[13] ) ? 1 : 0;
6297
6298
6299 int32_t ref = 0;
6300
6301 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6302 //Do we need to also check the render target and do the same thing if the
6303 //dest == -2 and the render target is not RT_SCREEN?
6304
6305 ref = sdci[DRAWCMD_BMP_TARGET];
6306
6307
6308 if ( ref <= 0 )
6309 {
6310 Z_scripterrlog("bitmap->DrawPlane() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6311 return;
6312 }
6313 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6314
6315 if(!sourceBitmap)
6316 {
6317 Z_message("Warning: %d->DrawPlane() source bitmap contains invalid data or is not initialized.\n", ref);
6318 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6319 return;
6320 }
6321
6322 BITMAP *destBMP=NULL;
6323 switch(bitmapIndex)
6324 {
6325 case -2:
6326 {
6327 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6328 if ( curr_rt >= 0 && curr_rt < 7 )
6329 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6330 else destBMP = bmp; //screen
6331 break;
6332 }
6333 case -1:
6334 destBMP = bmp; //this is framebuf, by default
6335 break;
6336
6337 //1 through 6 are the old system bitmaps (Render Targets)
6338 case 0:
6339 case 1:
6340 case 2:
6341 case 3:
6342 case 4:
6343 case 5:
6344 case 6:
6345 {
6346 //This gets a render target.
6347 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6348 break;
6349 }
6350 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6351 default:
6352 {
6353 auto& usr_bitmap = scb.get(usr_bitmap_index);
6354 destBMP = usr_bitmap.u_bmp;
6355 if ( !usr_bitmap.u_bmp )
6356 {
6357 Z_scripterrlog("Target for bitmap->DrawPlane is uninitialised. Aborting.\n");
6358 break;
6359 }
6360 }
6361 }
6362
6363 if (!destBMP)
6364 {
6365 Z_message("Warning: DrawPlane(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6366 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6367 return;
6368 }
6369
6370 //dx = dx + xoffset; //don't do this here!
6371 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6372 //All of these are a factor of 10000 as fix.
6373 int32_t screen_x = 0; int32_t screen_y = 0;
6374
6375 double distance = 0; double horizontal_scale = 0;
6376
6377 int32_t screen_y_horizon = 0;
6378
6379 double line_dx = 0; double line_dy = 0;
6380
6381 int32_t space_x = 0; int32_t space_y = 0;
6382
6383 for(screen_y = 0; screen_y < destH; screen_y++) //fix, offset by .0000
6384 {
6385 //Calculate the distance of each line from the camera point
6386 screen_y_horizon = screen_y + horizon;
6387
6388 distance = ((space_z * scale_y) / ((screen_y_horizon != 0) ? screen_y_horizon : 1));
6389
6390 //Get the scale of each line based on the distance
6391
6392 horizontal_scale = (distance / (( scale_x != 0 ) ? scale_x : 1));
6393
6394 //There was some math here before I stripped out the rotation step
6395 line_dx = horizontal_scale;
6396 line_dy = 0;
6397
6398 //space_x,space_y - where to grab each scanline from on the space bitmap
6399 space_x = srcX - destW/2.0 * line_dx;
6400 space_y = srcY - distance + destH/2.0 * line_dy;
6401
6402 //Keep blits within the bounds of both bitmaps to avoid crashes
6403 int32_t y1 = srcY+space_y;
6404 int32_t y2 = destY+screen_y;
6405 if(y1 >=0 && y1 <= (sourceBitmap->h-1) && y2 >=0 && y2 <= (destBMP->h-1) )
6406 {
6407 if ( masked ) masked_stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6408 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6409 else stretch_blit(sourceBitmap, destBMP, (int32_t)(srcX+space_x), (int32_t)(srcY+space_y),
6410 (int32_t)(line_dx*destW), 1, (int32_t)(screen_x), (int32_t)(screen_y)+yoffset, (int32_t)(destW), 1);
6411 }
6412 }
6413 }
6414
6415
6416 //Draw]()
6417 264439 void bmp_do_drawbitmapexr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
6418 {
6419 /*
6420 //sdci[1]=layer
6421 //sdci[2]=bitmap target
6422 //
6423 // -2 is the current Render Target
6424 // -1, this is the screen (framebuf).
6425 // 0: Render target 0
6426 // 1: Render target 1
6427 // 2: Render target 2
6428 // 3: Render target 3
6429 // 4: Render target 4
6430 // 5: Render target 5
6431 // 6: Render target 6
6432 // Otherwise: The pointer to a bitmap.
6433
6434 //sdci[3]=sourcex
6435 //sdci[4]=sourcey
6436 //sdci[5]=sourcew
6437 //sdci[6]=sourceh
6438 //sdci[7]=destx
6439 //sdci[8]=desty
6440 //sdci[9]=destw
6441 //sdci[10]=desth
6442 //sdci[11]=rotation/angle
6443 //scdi[12] = pivot cx
6444 //sdci[13] = pivot cy
6445 //scdi[14] = effect flags
6446 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
6447
6448 // ZScript-side constant values:
6449 const int32_t BITDX_NORMAL = 0;
6450 const int32_t BITDX_TRANS = 1; //Translucent
6451 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
6452 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
6453 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
6454 //Note: Some modes cannot be combined. if a combination is not supported, an error
6455 // detailing this will be shown in allegro.log.
6456
6457 //scdi[15] = litcolour
6458 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6459 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
6460
6461 //sdci[16]=mask
6462
6463 */
6464
6465 264439 int32_t bitmapIndex = sdci[2]/10000;
6466 264439 int32_t usr_bitmap_index = sdci[2];
6467
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if ( bitmapIndex > 10000 )
6468 {
6469 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
6470 }
6471
3/4
✓ Branch 0 taken 172223 times.
✓ Branch 1 taken 92216 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 172223 times.
264439 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
6472 {
6473 172223 bitmapIndex = usr_bitmap_index;
6474 172223 yoffset = 0;
6475 172223 }
6476
6477 264439 int32_t sx = sdci[3]/10000;
6478 264439 int32_t sy = sdci[4]/10000;
6479 264439 int32_t sw = sdci[5]/10000;
6480 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
6481 264439 int32_t sh = sdci[6]/10000;
6482 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
6483 264439 int32_t dx = sdci[7]/10000;
6484 264439 int32_t dy = sdci[8]/10000;
6485 264439 int32_t dw = sdci[9]/10000;
6486 264439 int32_t dh = sdci[10]/10000;
6487 264439 float rot = sdci[11]/10000;
6488 264439 int32_t cx = sdci[12]/10000;
6489 264439 int32_t cy = sdci[13]/10000;
6490 264439 int32_t mode = sdci[14]/10000;
6491 264439 int32_t litcolour = sdci[15]/10000;
6492 264439 bool masked = (sdci[16] != 0);
6493
6494 264439 int32_t ref = 0;
6495
6496 264439 dx = dx + xoffset;
6497 264439 dy = dy + yoffset;
6498
6499
2/4
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264439 times.
264439 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
6500 //Do we need to also check the render target and do the same thing if the
6501 //dest == -2 and the render target is not RT_SCREEN?
6502
6503 264439 ref = sdci[DRAWCMD_BMP_TARGET];
6504
6505
6506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264439 times.
264439 if ( ref <= 0 )
6507 {
6508 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
6509 return;
6510 }
6511 264439 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
6512
6513
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if(!sourceBitmap)
6514 {
6515
6516 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
6517 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6518 return;
6519 }
6520
6521 264439 BITMAP *destBMP=NULL;
6522
3/4
✗ Branch 0 not taken.
✓ Branch 1 taken 172223 times.
✓ Branch 2 taken 786 times.
✓ Branch 3 taken 91430 times.
264439 switch(bitmapIndex)
6523 {
6524 case -2:
6525 {
6526 786 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
6527
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 786 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
786 if ( curr_rt >= 0 && curr_rt < 7 )
6528 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
6529 786 else destBMP = bmp; //screen
6530 786 break;
6531 }
6532 case -1:
6533 91430 destBMP = bmp; //this is framebuf, by default
6534 91430 break;
6535 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
6536 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
6537 //destBMP = framebuf; //Drawing to the screen.
6538 //break;
6539
6540 //1 through 6 are the old system bitmaps (Render Targets)
6541 case 0:
6542 case 1:
6543 case 2:
6544 case 3:
6545 case 4:
6546 case 5:
6547 case 6:
6548 {
6549 //This gets a render target.
6550 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
6551
6552 //destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
6553 //sdci[18] = bitmapIndex;
6554 break;
6555 }
6556 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
6557 default:
6558 {
6559 172223 auto& usr_bitmap = scb.get(usr_bitmap_index);
6560 172223 destBMP = usr_bitmap.u_bmp;
6561 //sdci[18] = usr_bitmap_index;
6562
1/2
✓ Branch 0 taken 172223 times.
✗ Branch 1 not taken.
172223 if ( !usr_bitmap.u_bmp )
6563 {
6564 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
6565 break;
6566 }
6567 }
6568 172223 }
6569
6570
1/2
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
264439 if (!destBMP)
6571 {
6572 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
6573 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
6574 return;
6575 }
6576
6577
2/2
✓ Branch 0 taken 1027 times.
✓ Branch 1 taken 263412 times.
264439 bool stretched = (sw != dw || sh != dh);
6578 264439 BITMAP* subBmp = 0;
6579
6580
4/4
✓ Branch 0 taken 262860 times.
✓ Branch 1 taken 1579 times.
✓ Branch 2 taken 24983 times.
✓ Branch 3 taken 237877 times.
264439 if(rot != 0 || mode != 0)
6581 {
6582 26562 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
6583 26562 clear_bitmap(subBmp);
6584
6585
1/2
✓ Branch 0 taken 26562 times.
✗ Branch 1 not taken.
26562 if(!subBmp)
6586 {
6587
6588 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
6589 return;
6590 }
6591 26562 }
6592 264439 BITMAP* sbmp = sourceBitmap;
6593
2/4
✓ Branch 0 taken 264439 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 264439 times.
264439 if (sx + sw > sbmp->w || sy + sh > sbmp->h)
6594 {
6595 sbmp = create_bitmap_ex(8, sw, sh);
6596 clear_bitmap(sbmp);
6597 blit(sourceBitmap, sbmp, sx, sy, 0, 0, std::min(sourceBitmap->w-sx, sw), std::min(sourceBitmap->h-sy, sh));
6598 sx = 0;
6599 sy = 0;
6600 }
6601 //dx = dx + xoffset; //don't do this here!
6602 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
6603
6604
2/2
✓ Branch 0 taken 1602 times.
✓ Branch 1 taken 262837 times.
264439 if(stretched)
6605 {
6606
2/2
✓ Branch 0 taken 1475 times.
✓ Branch 1 taken 127 times.
1602 if(masked)
6607 { //stretched and masked
6608
2/2
✓ Branch 0 taken 574 times.
✓ Branch 1 taken 901 times.
1475 if ( rot == 0 )
6609 { //if not rotated
6610
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 900 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 1 times.
901 switch(mode)
6611 {
6612 case 1:
6613 //transparent
6614 900 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6615 900 draw_trans_sprite(destBMP, subBmp, dx, dy);
6616 900 break;
6617
6618
6619 case 2:
6620 //pivot?
6621 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6622 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6623 //Pivoting requires two more args
6624 break;
6625
6626 case 3:
6627 //pivot + trans
6628 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6629 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6630 break;
6631
6632 case 4:
6633 //flip v
6634 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6635 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6636 break;
6637
6638 case 5:
6639 //trans + v flip
6640 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6641 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6642 break;
6643
6644 case 6:
6645 //pivot + v flip
6646 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6647 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6648 break;
6649
6650 case 8:
6651 //vlip h
6652 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6653 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6654 break;
6655
6656 case 9:
6657 //trans + h flip
6658 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6659 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6660 break;
6661
6662 case 10:
6663 //flip H and pivot
6664 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6665 //return error cannot pivot and h flip
6666 break;
6667
6668 case 12:
6669 //vh flip
6670 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6671 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6672 break;
6673
6674 case 13:
6675 //trans + vh flip
6676 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6677 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6678 break;
6679
6680 case 14:
6681 //pivot and vh flip
6682 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6683 //return error cannot both pivot and vh flip
6684 break;
6685
6686 case 16:
6687 //lit
6688 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6689 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6690 break;
6691
6692 case 18:
6693 //pivot, lit
6694 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6695 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6696 break;
6697
6698 case 20:
6699 //lit + v flip
6700 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6701 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6702 break;
6703
6704 case 22:
6705 //Pivot, vflip, lit
6706 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6707 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6708 break;
6709
6710 case 24:
6711 //lit + h flip
6712 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6713 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6714 break;
6715
6716 case 26:
6717 //pivot + lit + hflip
6718 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
6719 //return error cannot pivot, lit, and flip
6720 break;
6721
6722 case 28:
6723 //lit + vh flip
6724 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6725 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
6726 break;
6727
6728 case 32: //gouraud
6729 //Probably not wort supporting.
6730 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6731 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6732 break;
6733
6734 case 0:
6735 //no effect
6736 1 masked_stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
6737 1 break;
6738
6739
6740 default:
6741
6742 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6743
6744
6745 }
6746 901 } //end if not rotated
6747
6748
2/2
✓ Branch 0 taken 901 times.
✓ Branch 1 taken 574 times.
1475 if ( rot != 0 ) //if rotated
6749 {
6750
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 574 times.
✗ Branch 21 not taken.
574 switch(mode)
6751 {
6752 case 1:
6753 //transparent
6754 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6755 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6756
6757 break;
6758
6759 case 2:
6760 //pivot?
6761 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6762 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6763 //Pivoting requires two more args
6764 break;
6765
6766 case 3:
6767 //pivot + trans
6768 //return an error, cannot both rotate and pivot
6769 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6770 break;
6771
6772 case 4:
6773 //flip v
6774 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6775 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6776 break;
6777
6778 case 5:
6779 //trans + v flip
6780 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6781 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6782 break;
6783
6784 case 6:
6785 //pivot + v flip
6786 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6787 //return an error, cannot both rotate and pivot
6788 break;
6789
6790 case 8:
6791 //flip h
6792 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
6793 //return an error, cannot both rotate and flip H
6794 break;
6795
6796 case 9:
6797 //trans + h flip
6798 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
6799 //return an error, cannot rotate and flip a trans sprite
6800 break;
6801
6802 case 10:
6803 //flip H and pivot
6804 //return error cannot pivot and h flip
6805 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6806 break;
6807
6808 case 12:
6809 //vh flip
6810 //return an error, cannot rotate and VH flip a trans sprite
6811 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6812 break;
6813
6814 case 13:
6815 //trans + vh flip
6816 //return an error, cannot rotate and VH flip a trans sprite
6817 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
6818 break;
6819
6820 case 14:
6821 //pivot and vh flip
6822 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6823 //return error cannot both pivot and vh flip
6824 break;
6825
6826 case 16:
6827 //lit
6828 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6829 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6830 break;
6831
6832 case 18:
6833 //pivot, lit
6834 //return an error, cannot both rotate and pivot
6835 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
6836 break;
6837
6838 case 20:
6839 //lit + vflip
6840 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6841 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
6842 break;
6843
6844 case 22:
6845 //Pivot, vflip, lit
6846 //return an error, cannot both rotate and pivot
6847 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
6848 break;
6849
6850 case 24:
6851 //lit + h flip
6852 //return an error, cannot both rotate and H flip
6853 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
6854 break;
6855
6856 case 26:
6857 //pivot + lit + hflip
6858 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
6859 //return error cannot pivot, lit, and flip
6860 break;
6861
6862 case 28:
6863 //lit + vh flip
6864 //return an error, cannot both rotate and VH flip
6865 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6866 break;
6867
6868 case 32: //gouraud
6869 //Probably not wort supporting.
6870 //masked_stretch_blit(sourceBitmap, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6871 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
6872 break;
6873
6874 case 0:
6875 //no effect.
6876 574 masked_stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6877 574 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
6878 574 break;
6879
6880 default:
6881
6882 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
6883
6884 }
6885 574 }
6886 1475 } //end if stretched and masked
6887
6888 else //stretched, not masked
6889 {
6890
6891
6892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 127 times.
127 if ( rot == 0 ) //if not rotated
6893 {
6894
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 127 times.
127 switch(mode)
6895 {
6896 case 1:
6897 //transparent
6898 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6899 draw_trans_sprite(destBMP, subBmp, dx, dy);
6900 break;
6901
6902
6903 case 2:
6904 //pivot?
6905 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6906 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6907 //Pivoting requires two more args
6908 break;
6909
6910 case 3:
6911 //pivot + trans
6912 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6913 pivot_sprite_trans(destBMP, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
6914 break;
6915
6916 case 4:
6917 //flip v
6918 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6919 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
6920 break;
6921
6922 case 5:
6923 //trans + v flip
6924 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6925 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
6926 break;
6927
6928 case 6:
6929 //pivot + v flip
6930 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6931 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
6932 break;
6933
6934 case 8:
6935 //vlip h
6936 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6937 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
6938 break;
6939
6940 case 9:
6941 //trans + h flip
6942 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6943 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
6944 break;
6945
6946 case 10:
6947 //flip H and pivot
6948 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
6949 //return error cannot pivot and h flip
6950 break;
6951
6952 case 12:
6953 //vh flip
6954 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6955 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
6956 break;
6957
6958 case 13:
6959 //trans + vh flip
6960 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6961 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
6962 break;
6963
6964 case 14:
6965 //pivot and vh flip
6966 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
6967 //return error cannot both pivot and vh flip
6968 break;
6969
6970 case 16:
6971 //lit
6972 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6973 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
6974 break;
6975
6976 case 18:
6977 //pivot, lit
6978 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6979 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6980 break;
6981
6982 case 20:
6983 //lit + v flip
6984 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6985 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
6986 break;
6987
6988 case 22:
6989 //Pivot, vflip, lit
6990 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6991 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
6992 break;
6993
6994 case 24:
6995 //lit + h flip
6996 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
6997 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
6998 break;
6999
7000 case 26:
7001 //pivot + lit + hflip
7002 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7003 //return error cannot pivot, lit, and flip
7004 break;
7005
7006 case 28:
7007 //lit + vh flip
7008 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7009 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7010 break;
7011
7012 case 32: //gouraud
7013 //Probably not wort supporting.
7014 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7015 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7016 break;
7017
7018 case 0:
7019 //no effect
7020 127 stretch_blit(sbmp, destBMP, sx, sy, sw, sh, dx, dy, dw, dh);
7021 127 break;
7022
7023
7024 default:
7025
7026 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7027
7028
7029 }
7030 127 } //end if not rotated
7031
7032
1/2
✓ Branch 0 taken 127 times.
✗ Branch 1 not taken.
127 if ( rot != 0 ) //if rotated
7033 {
7034 switch(mode)
7035 {
7036 case 1:
7037 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7038 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7039
7040 break;
7041
7042 case 2:
7043 //pivot?
7044 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7045 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7046 //Pivoting requires two more args
7047 break;
7048
7049 case 3:
7050 //pivot + trans
7051 //return an error, cannot both rotate and pivot
7052 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7053 break;
7054
7055 case 4:
7056 //flip v
7057 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7058 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7059 break;
7060
7061 case 5:
7062 //trans + v flip
7063 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7064 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7065 break;
7066
7067 case 6:
7068 //pivot + v flip
7069 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7070 //return an error, cannot both rotate and pivot
7071 break;
7072
7073 case 8:
7074 //flip h
7075 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7076 //return an error, cannot both rotate and flip H
7077 break;
7078
7079 case 9:
7080 //trans + h flip
7081 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7082 //return an error, cannot rotate and flip a trans sprite
7083 break;
7084
7085 case 10:
7086 //flip H and pivot
7087 //return error cannot pivot and h flip
7088 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7089 break;
7090
7091 case 12:
7092 //vh flip
7093 //return an error, cannot rotate and VH flip a trans sprite
7094 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7095 break;
7096
7097 case 13:
7098 //trans + vh flip
7099 //return an error, cannot rotate and VH flip a trans sprite
7100 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7101 break;
7102
7103 case 14:
7104 //pivot and vh flip
7105 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7106 //return error cannot both pivot and vh flip
7107 break;
7108
7109 case 16:
7110 //lit
7111 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7112 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7113 break;
7114
7115 case 18:
7116 //pivot, lit
7117 //return an error, cannot both rotate and pivot
7118 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7119 break;
7120
7121 case 20:
7122 //lit + vflip
7123 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
7124 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7125 break;
7126
7127 case 22:
7128 //Pivot, vflip, lit
7129 //return an error, cannot both rotate and pivot
7130 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7131 break;
7132
7133 case 24:
7134 //lit + h flip
7135 //return an error, cannot both rotate and H flip
7136 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7137 break;
7138
7139 case 26:
7140 //pivot + lit + hflip
7141 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7142 //return error cannot pivot, lit, and flip
7143 break;
7144
7145 case 28:
7146 //lit + vh flip
7147 //return an error, cannot both rotate and VH flip
7148 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7149 break;
7150
7151 case 32: //gouraud
7152 //Probably not wort supporting.
7153 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7154 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7155 break;
7156
7157 case 0:
7158 //no effect.
7159 stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7160 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7161 break;
7162
7163 default:
7164
7165 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7166
7167 }
7168 }
7169
7170 } //end if stretched, but not masked
7171 1602 }
7172 else //not stretched
7173 {
7174
7175
2/2
✓ Branch 0 taken 251854 times.
✓ Branch 1 taken 10983 times.
262837 if(masked) //if masked, but not stretched
7176 {
7177
7178
2/2
✓ Branch 0 taken 1005 times.
✓ Branch 1 taken 250849 times.
251854 if ( rot == 0 ) //if not rotated
7179 {
7180
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 18689 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 232160 times.
250849 switch(mode)
7181 {
7182 case 1:
7183 //transparent
7184 18689 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7185 18689 draw_trans_sprite(destBMP, subBmp, dx, dy);
7186 18689 break;
7187
7188
7189 case 2:
7190 //pivot?
7191 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7192 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7193 //Pivoting requires two more args
7194 break;
7195
7196 case 3:
7197 //pivot + trans
7198 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7199 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7200 break;
7201
7202 case 4:
7203 //flip v
7204 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7205 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7206 break;
7207
7208 case 5:
7209 //trans + v flip
7210 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7211 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7212 break;
7213
7214 case 6:
7215 //pivot + v flip
7216 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7217 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7218 break;
7219
7220 case 8:
7221 //vlip h
7222 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7223 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7224 break;
7225
7226 case 9:
7227 //trans + h flip
7228 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7229 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7230 break;
7231
7232 case 10:
7233 //flip H and pivot
7234 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7235 //return error cannot pivot and h flip
7236 break;
7237
7238 case 12:
7239 //vh flip
7240 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7241 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7242 break;
7243
7244 case 13:
7245 //trans + vh flip
7246 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7247 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7248 break;
7249
7250 case 14:
7251 //pivot and vh flip
7252 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7253 //return error cannot both pivot and vh flip
7254 break;
7255
7256 case 16:
7257 //lit
7258 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7259 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7260 break;
7261
7262 case 18:
7263 //pivot, lit
7264 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7265 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7266 break;
7267
7268 case 20:
7269 //lit + v flip
7270 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7271 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7272 break;
7273
7274 case 22:
7275 //Pivot, vflip, lit
7276 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7277 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7278 break;
7279
7280 case 24:
7281 //lit + h flip
7282 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7283 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7284 break;
7285
7286 case 26:
7287 //pivot + lit + hflip
7288 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7289 //return error cannot pivot, lit, and flip
7290 break;
7291
7292 case 28:
7293 //lit + vh flip
7294 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7295 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7296 break;
7297
7298 case 32: //gouraud
7299 //Probably not wort supporting.
7300 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7301 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7302 break;
7303
7304 case 0:
7305 //no effect
7306 232160 masked_blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7307 232160 break;
7308
7309
7310 default:
7311
7312 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7313
7314
7315 }
7316 250849 } //end if not rotated
7317
7318
2/2
✓ Branch 0 taken 250849 times.
✓ Branch 1 taken 1005 times.
251854 if ( rot != 0 ) //if rotated
7319 {
7320
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 1005 times.
✗ Branch 21 not taken.
1005 switch(mode)
7321 {
7322 case 1:
7323 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
7324 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7325
7326 break;
7327
7328 case 2:
7329 //pivot?
7330 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7331 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7332 //Pivoting requires two more args
7333 break;
7334
7335 case 3:
7336 //pivot + trans
7337 //return an error, cannot both rotate and pivot
7338 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7339 break;
7340
7341 case 4:
7342 //flip v
7343 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7344 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7345 break;
7346
7347 case 5:
7348 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
7349 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7350 break;
7351
7352 case 6:
7353 //pivot + v flip
7354 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7355 //return an error, cannot both rotate and pivot
7356 break;
7357
7358 case 8:
7359 //flip h
7360 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7361 //return an error, cannot both rotate and flip H
7362 break;
7363
7364 case 9:
7365 //trans + h flip
7366 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7367 //return an error, cannot rotate and flip a trans sprite
7368 break;
7369
7370 case 10:
7371 //flip H and pivot
7372 //return error cannot pivot and h flip
7373 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7374 break;
7375
7376 case 12:
7377 //vh flip
7378 //return an error, cannot rotate and VH flip a trans sprite
7379 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7380 break;
7381
7382 case 13:
7383 //trans + vh flip
7384 //return an error, cannot rotate and VH flip a trans sprite
7385 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7386 break;
7387
7388 case 14:
7389 //pivot and vh flip
7390 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7391 //return error cannot both pivot and vh flip
7392 break;
7393
7394 case 16:
7395 //lit
7396 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7397 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7398 break;
7399
7400 case 18:
7401 //pivot, lit
7402 //return an error, cannot both rotate and pivot
7403 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7404 break;
7405
7406 case 20:
7407 //lit + vflip
7408 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7409 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7410 break;
7411
7412 case 22:
7413 //Pivot, vflip, lit
7414 //return an error, cannot both rotate and pivot
7415 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7416 break;
7417
7418 case 24:
7419 //lit + h flip
7420 //return an error, cannot both rotate and H flip
7421 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7422 break;
7423
7424 case 26:
7425 //pivot + lit + hflip
7426 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7427 //return error cannot pivot, lit, and flip
7428 break;
7429
7430 case 28:
7431 //lit + vh flip
7432 //return an error, cannot both rotate and VH flip
7433 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7434 break;
7435
7436 case 32: //gouraud
7437 //Probably not wort supporting.
7438 //stretch_blit(sbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7439 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7440 break;
7441
7442 case 0:
7443 //no effect.
7444 1005 masked_blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7445 1005 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7446 1005 break;
7447
7448 default:
7449
7450 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7451
7452 }
7453 1005 } //end rtated, masked
7454 251854 } //end if masked
7455
7456 else //not masked, and not stretched; just blit
7457 {
7458
7459
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10983 times.
10983 if ( rot == 0 ) //if not rotated
7460 {
7461
2/22
✗ Branch 0 not taken.
✓ Branch 1 taken 5394 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 5589 times.
10983 switch(mode)
7462 {
7463 case 1:
7464 //transparent
7465 5394 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7466 5394 draw_trans_sprite(destBMP, subBmp, dx, dy);
7467 5394 break;
7468
7469
7470 case 2:
7471 //pivot?
7472 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7473 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7474 //Pivoting requires two more args
7475 break;
7476
7477 case 3:
7478 //pivot + trans
7479 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7480 pivot_sprite_trans(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7481 break;
7482
7483 case 4:
7484 //flip v
7485 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7486 draw_sprite_v_flip(destBMP, subBmp, dx, dy);
7487 break;
7488
7489 case 5:
7490 //trans + v flip
7491 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7492 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7493 break;
7494
7495 case 6:
7496 //pivot + v flip
7497 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7498 pivot_sprite_v_flip(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7499 break;
7500
7501 case 8:
7502 //vlip h
7503 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7504 draw_sprite_h_flip(destBMP, subBmp, dx, dy);
7505 break;
7506
7507 case 9:
7508 //trans + h flip
7509 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7510 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
7511 break;
7512
7513 case 10:
7514 //flip H and pivot
7515 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7516 //return error cannot pivot and h flip
7517 break;
7518
7519 case 12:
7520 //vh flip
7521 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7522 draw_sprite_vh_flip(destBMP, subBmp, dx, dy);
7523 break;
7524
7525 case 13:
7526 //trans + vh flip
7527 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7528 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
7529 break;
7530
7531 case 14:
7532 //pivot and vh flip
7533 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7534 //return error cannot both pivot and vh flip
7535 break;
7536
7537 case 16:
7538 //lit
7539 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7540 draw_lit_sprite(destBMP, subBmp, dx, dy, litcolour);
7541 break;
7542
7543 case 18:
7544 //pivot, lit
7545 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7546 pivot_sprite_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7547 break;
7548
7549 case 20:
7550 //lit + v flip
7551 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7552 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
7553 break;
7554
7555 case 22:
7556 //Pivot, vflip, lit
7557 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7558 pivot_sprite_v_flip_lit(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
7559 break;
7560
7561 case 24:
7562 //lit + h flip
7563 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7564 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
7565 break;
7566
7567 case 26:
7568 //pivot + lit + hflip
7569 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
7570 //return error cannot pivot, lit, and flip
7571 break;
7572
7573 case 28:
7574 //lit + vh flip
7575 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7576 draw_sprite_ex(destBMP, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
7577 break;
7578
7579 case 32: //gouraud
7580 //Probably not wort supporting.
7581 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7582 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7583 break;
7584
7585 case 0:
7586 //no effect
7587 5589 blit(sbmp, destBMP, sx, sy, dx, dy, dw, dh);
7588 5589 break;
7589
7590
7591 default:
7592
7593 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7594
7595
7596 }
7597 10983 } //end if not rotated
7598
7599
1/2
✓ Branch 0 taken 10983 times.
✗ Branch 1 not taken.
10983 if ( rot != 0 ) //if rotated
7600 {
7601 switch(mode)
7602 {
7603 case 1:
7604 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
7605 rotate_sprite_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7606
7607 break;
7608
7609 case 2:
7610 //pivot?
7611 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7612 pivot_sprite(destBMP, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7613 //Pivoting requires two more args
7614 break;
7615
7616 case 3:
7617 //pivot + trans
7618 //return an error, cannot both rotate and pivot
7619 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7620 break;
7621
7622 case 4:
7623 //flip v
7624 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7625 rotate_sprite_v_flip(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7626 break;
7627
7628 case 5:
7629 //trans + v flip
7630 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7631 rotate_sprite_v_flip_trans(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7632 break;
7633
7634 case 6:
7635 //pivot + v flip
7636 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7637 //return an error, cannot both rotate and pivot
7638 break;
7639
7640 case 8:
7641 //flip h
7642 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
7643 //return an error, cannot both rotate and flip H
7644 break;
7645
7646 case 9:
7647 //trans + h flip
7648 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
7649 //return an error, cannot rotate and flip a trans sprite
7650 break;
7651
7652 case 10:
7653 //flip H and pivot
7654 //return error cannot pivot and h flip
7655 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
7656 break;
7657
7658 case 12:
7659 //vh flip
7660 //return an error, cannot rotate and VH flip a trans sprite
7661 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7662 break;
7663
7664 case 13:
7665 //trans + vh flip
7666 //return an error, cannot rotate and VH flip a trans sprite
7667 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
7668 break;
7669
7670 case 14:
7671 //pivot and vh flip
7672 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7673 //return error cannot both pivot and vh flip
7674 break;
7675
7676 case 16:
7677 //lit
7678 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7679 rotate_sprite_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7680 break;
7681
7682 case 18:
7683 //pivot, lit
7684 //return an error, cannot both rotate and pivot
7685 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
7686 break;
7687
7688 case 20:
7689 //lit + vflip
7690 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7691 rotate_sprite_v_flip_lit(destBMP, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7692 break;
7693
7694 case 22:
7695 //Pivot, vflip, lit
7696 //return an error, cannot both rotate and pivot
7697 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
7698 break;
7699
7700 case 24:
7701 //lit + h flip
7702 //return an error, cannot both rotate and H flip
7703 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
7704 break;
7705
7706 case 26:
7707 //pivot + lit + hflip
7708 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
7709 //return error cannot pivot, lit, and flip
7710 break;
7711
7712 case 28:
7713 //lit + vh flip
7714 //return an error, cannot both rotate and VH flip
7715 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
7716 break;
7717
7718 case 32: //gouraud
7719 //Probably not wort supporting.
7720 //blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7721 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
7722 break;
7723
7724 case 0:
7725 //no effect.
7726 blit(sbmp, subBmp, sx, sy, 0, 0, dw, dh);
7727 rotate_sprite(destBMP, subBmp, dx, dy, degrees_to_fixed(rot));
7728 break;
7729
7730 default:
7731
7732 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
7733
7734 }
7735 } //end if rotated
7736 } //end if not masked
7737 } //end if not stretched
7738
7739 //cleanup
7740
2/2
✓ Branch 0 taken 26562 times.
✓ Branch 1 taken 237877 times.
264439 if(subBmp)
7741 {
7742 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
7743 26562 destroy_bitmap(subBmp);
7744 26562 }
7745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 264439 times.
264439 if (sbmp != sourceBitmap)
7746 {
7747 destroy_bitmap(sbmp);
7748 }
7749 264439 }
7750
7751
7752
7753 113329 void bmp_do_blittor(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset)
7754 {
7755 /*
7756 //sdci[1]=layer
7757 //sdci[2]=bitmap target
7758 //
7759 // -2 is the current Render Target
7760 // -1, this is the screen (framebuf).
7761 // 0: Render target 0
7762 // 1: Render target 1
7763 // 2: Render target 2
7764 // 3: Render target 3
7765 // 4: Render target 4
7766 // 5: Render target 5
7767 // 6: Render target 6
7768 // Otherwise: The pointer to a bitmap.
7769
7770 //sdci[3]=sourcex
7771 //sdci[4]=sourcey
7772 //sdci[5]=sourcew
7773 //sdci[6]=sourceh
7774 //sdci[7]=destx
7775 //sdci[8]=desty
7776 //sdci[9]=destw
7777 //sdci[10]=desth
7778 //sdci[11]=rotation/angle
7779 //scdi[12] = pivot cx
7780 //sdci[13] = pivot cy
7781 //scdi[14] = effect flags
7782 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
7783
7784 // ZScript-side constant values:
7785 const int32_t BITDX_NORMAL = 0;
7786 const int32_t BITDX_TRANS = 1; //Translucent
7787 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
7788 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
7789 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
7790 //Note: Some modes cannot be combined. if a combination is not supported, an error
7791 // detailing this will be shown in allegro.log.
7792
7793 //scdi[15] = litcolour
7794 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
7795 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
7796
7797 //sdci[16]=mask
7798
7799 */
7800
7801 113329 int32_t srcyoffset = yoffset, srcxoffset = xoffset;
7802 113329 int32_t bitmapIndex = sdci[2]/10000;
7803 113329 int32_t usr_bitmap_index = sdci[2];
7804
7805
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if ( bitmapIndex > 10000 )
7806 {
7807 bitmapIndex = bitmapIndex / 10000; //reduce if ZScript sent a raw value, such as bitmap = <int32_t> 8;
7808 }
7809
3/4
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 113326 times.
113329 if ( usr_bitmap_index > 0 && usr_bitmap_index < 10000 )
7810 {
7811 113326 bitmapIndex = usr_bitmap_index;
7812 113326 srcyoffset = 0;
7813 113326 }
7814
7815 113329 int32_t sx = sdci[3]/10000;
7816 113329 int32_t sy = sdci[4]/10000;
7817 113329 int32_t sw = sdci[5]/10000;
7818 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
7819 113329 int32_t sh = sdci[6]/10000;
7820 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
7821 113329 int32_t dx = sdci[7]/10000;
7822 113329 int32_t dy = sdci[8]/10000;
7823 113329 int32_t dw = sdci[9]/10000;
7824 113329 int32_t dh = sdci[10]/10000;
7825 113329 float rot = sdci[11]/10000;
7826 113329 int32_t cx = sdci[12]/10000;
7827 113329 int32_t cy = sdci[13]/10000;
7828 113329 int32_t mode = sdci[14]/10000;
7829 113329 int32_t litcolour = sdci[15]/10000;
7830 113329 bool masked = (sdci[16] != 0);
7831
7832 113329 int32_t ref = 0;
7833
7834 //These should go down farther, should they not? -V
7835 //dx = dx + xoffset;
7836 //dy = dy + yoffset;
7837
7838
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
7839
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if ( (bitmapIndex) != -2 && (bitmapIndex) != -1 ) srcyoffset = 0; //Don't crop.
7840 //Do we need to also check the render target and do the same thing if the
7841 //dest == -2 and the render target is not RT_SCREEN?
7842 113329 dx = dx + xoffset;
7843 113329 dy = dy + yoffset;
7844 113329 sx = sx + srcxoffset;
7845 113329 sy = sy + srcyoffset;
7846
7847 113329 ref = sdci[DRAWCMD_BMP_TARGET];
7848
7849
7850
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if ( ref <= 0 )
7851 {
7852 Z_scripterrlog("bitmap->blit() wanted to use to an invalid source bitmap id: %d. Aborting.\n", ref);
7853 return;
7854 }
7855 113329 BITMAP *sourceBitmap = FFCore.GetScriptBitmap(ref); //This can be the screen, as -1.
7856
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if(!sourceBitmap)
7857 {
7858 Z_message("Warning: blit(%d) source bitmap contains invalid data or is not initialized.\n", ref);
7859 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7860 return;
7861 }
7862
7863 113329 BITMAP *destBMP=NULL;
7864
7865
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
113329 switch(bitmapIndex)
7866 {
7867 case -2:
7868 {
7869 int32_t curr_rt = zscriptDrawingRenderTarget->GetCurrentRenderTarget();
7870 if ( curr_rt >= 0 && curr_rt < 7 )
7871 destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); //Drawing to the current RenderTarget.
7872 else destBMP = bmp; //screen
7873 break;
7874 }
7875 case -1:
7876 3 destBMP = bmp; //this is framebuf, by default
7877 3 break;
7878 //zscriptDrawingRenderTarget->SetCurrentRenderTarget(bitmapIndex);
7879 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex);
7880 //destBMP = framebuf; //Drawing to the screen.
7881 //break;
7882
7883 //1 through 6 are the old system bitmaps (Render Targets)
7884 case 0:
7885 case 1:
7886 case 2:
7887 case 3:
7888 case 4:
7889 case 5:
7890 case 6:
7891 {
7892 //This gets a render target.
7893 //destBMP = zscriptDrawingRenderTarget->GetBitmapPtr(bitmapIndex); break;
7894
7895 destBMP = zscriptDrawingRenderTarget->GetTargetBitmap(bitmapIndex);
7896 //sdci[18] = bitmapIndex;
7897 break;
7898 }
7899 //Otherwise, we are using a user-created bitmap, so, get that pointer insted.
7900 default:
7901 {
7902 113326 auto& usr_bitmap = scb.get(usr_bitmap_index);
7903 113326 destBMP = usr_bitmap.u_bmp;
7904 //sdci[18] = usr_bitmap_index;
7905
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( !usr_bitmap.u_bmp )
7906 {
7907 Z_scripterrlog("Target for bitmap->Blit is uninitialised. Aborting.\n");
7908 break;
7909 }
7910 }
7911 113326 }
7912
7913
1/2
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
113329 if (!destBMP)
7914 {
7915 Z_message("Warning: blit(%d) destination bitmap contains invalid data or is not initialized.\n", bitmapIndex);
7916 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
7917 return;
7918 }
7919
7920
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 bool stretched = (sw != dw || sh != dh);
7921
7922 113329 BITMAP* newDest = sourceBitmap;
7923 113329 BITMAP* newSource = destBMP; //Flip them.
7924
7925 113329 BITMAP* subBmp = 0;
7926
7927
2/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 113329 times.
113329 if(rot != 0 || mode != 0)
7928 {
7929 subBmp = create_bitmap_ex(8,sourceBitmap->w, sourceBitmap->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
7930 clear_bitmap(subBmp);
7931
7932 if(!subBmp)
7933 {
7934 Z_scripterrlog("bitmap->Blit failed to create a sub-bitmap to use for %s. Aborting.\n", "rotation");
7935 return;
7936 }
7937 }
7938
7939
3/4
✓ Branch 0 taken 113329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✓ Branch 3 taken 113326 times.
113329 if (sx + sw > destBMP->w || sy + sh > destBMP->h)
7940 {
7941 3 newSource = create_bitmap_ex(8, sw, sh);
7942 3 clear_bitmap(newSource);
7943 3 blit(destBMP, newSource, sx, sy, 0, 0, std::min(destBMP->w-sx, sw), std::min(destBMP->h-sy, sh));
7944 3 sx = 0;
7945 3 sy = 0;
7946 3 }
7947 //dx = dx + xoffset; //don't do this here!
7948 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
7949
7950
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(stretched)
7951 {
7952 if(masked)
7953 { //stretched and masked
7954 if ( rot == 0 )
7955 { //if not rotated
7956 switch(mode)
7957 {
7958 case 1:
7959 //transparent
7960 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7961 draw_trans_sprite(newDest, subBmp, dx, dy);
7962 break;
7963
7964
7965 case 2:
7966 //pivot?
7967 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7968 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7969 //Pivoting requires two more args
7970 break;
7971
7972 case 3:
7973 //pivot + trans
7974 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7975 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7976 break;
7977
7978 case 4:
7979 //flip v
7980 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7981 draw_sprite_v_flip(newDest, subBmp, dx, dy);
7982 break;
7983
7984 case 5:
7985 //trans + v flip
7986 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7987 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
7988 break;
7989
7990 case 6:
7991 //pivot + v flip
7992 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7993 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
7994 break;
7995
7996 case 8:
7997 //vlip h
7998 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
7999 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8000 break;
8001
8002 case 9:
8003 //trans + h flip
8004 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8005 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8006 break;
8007
8008 case 10:
8009 //flip H and pivot
8010 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8011 //return error cannot pivot and h flip
8012 break;
8013
8014 case 12:
8015 //vh flip
8016 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8017 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8018 break;
8019
8020 case 13:
8021 //trans + vh flip
8022 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8023 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8024 break;
8025
8026 case 14:
8027 //pivot and vh flip
8028 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8029 //return error cannot both pivot and vh flip
8030 break;
8031
8032 case 16:
8033 //lit
8034 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8035 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8036 break;
8037
8038 case 18:
8039 //pivot, lit
8040 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8041 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8042 break;
8043
8044 case 20:
8045 //lit + v flip
8046 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8047 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8048 break;
8049
8050 case 22:
8051 //Pivot, vflip, lit
8052 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8053 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8054 break;
8055
8056 case 24:
8057 //lit + h flip
8058 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8059 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8060 break;
8061
8062 case 26:
8063 //pivot + lit + hflip
8064 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8065 //return error cannot pivot, lit, and flip
8066 break;
8067
8068 case 28:
8069 //lit + vh flip
8070 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8071 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8072 break;
8073
8074 case 32: //gouraud
8075 //Probably not wort supporting.
8076 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8077 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8078 break;
8079
8080 case 0:
8081 //no effect
8082 masked_stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8083 break;
8084
8085
8086 default:
8087 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8088
8089
8090 }
8091 } //end if not rotated
8092
8093 if ( rot != 0 ) //if rotated
8094 {
8095 switch(mode)
8096 {
8097 case 1:
8098 //transparent
8099 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8100 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8101
8102 break;
8103
8104 case 2:
8105 //pivot?
8106 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8107 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8108 //Pivoting requires two more args
8109 break;
8110
8111 case 3:
8112 //pivot + trans
8113 //return an error, cannot both rotate and pivot
8114 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8115 break;
8116
8117 case 4:
8118 //flip v
8119 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8120 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8121 break;
8122
8123 case 5:
8124 //trans + v flip
8125 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8126 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8127 break;
8128
8129 case 6:
8130 //pivot + v flip
8131 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8132 //return an error, cannot both rotate and pivot
8133 break;
8134
8135 case 8:
8136 //flip h
8137 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8138 //return an error, cannot both rotate and flip H
8139 break;
8140
8141 case 9:
8142 //trans + h flip
8143 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8144 //return an error, cannot rotate and flip a trans sprite
8145 break;
8146
8147 case 10:
8148 //flip H and pivot
8149 //return error cannot pivot and h flip
8150 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8151 break;
8152
8153 case 12:
8154 //vh flip
8155 //return an error, cannot rotate and VH flip a trans sprite
8156 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8157 break;
8158
8159 case 13:
8160 //trans + vh flip
8161 //return an error, cannot rotate and VH flip a trans sprite
8162 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8163 break;
8164
8165 case 14:
8166 //pivot and vh flip
8167 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8168 //return error cannot both pivot and vh flip
8169 break;
8170
8171 case 16:
8172 //lit
8173 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8174 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8175 break;
8176
8177 case 18:
8178 //pivot, lit
8179 //return an error, cannot both rotate and pivot
8180 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8181 break;
8182
8183 case 20:
8184 //lit + vflip
8185 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8186 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8187 break;
8188
8189 case 22:
8190 //Pivot, vflip, lit
8191 //return an error, cannot both rotate and pivot
8192 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8193 break;
8194
8195 case 24:
8196 //lit + h flip
8197 //return an error, cannot both rotate and H flip
8198 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8199 break;
8200
8201 case 26:
8202 //pivot + lit + hflip
8203 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8204 //return error cannot pivot, lit, and flip
8205 break;
8206
8207 case 28:
8208 //lit + vh flip
8209 //return an error, cannot both rotate and VH flip
8210 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8211 break;
8212
8213 case 32: //gouraud
8214 //Probably not wort supporting.
8215 //masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8216 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8217 break;
8218
8219 case 0:
8220 //no effect.
8221 masked_stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8222 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8223 break;
8224
8225 default:
8226 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8227
8228 }
8229 }
8230 } //end if stretched and masked
8231
8232 else //stretched, not masked
8233 {
8234
8235
8236 if ( rot == 0 ) //if not rotated
8237 {
8238 switch(mode)
8239 {
8240 case 1:
8241 //transparent
8242 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8243 draw_trans_sprite(newDest, subBmp, dx, dy);
8244 break;
8245
8246
8247 case 2:
8248 //pivot?
8249 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8250 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8251 //Pivoting requires two more args
8252 break;
8253
8254 case 3:
8255 //pivot + trans
8256 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8257 pivot_sprite_trans(newDest, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
8258 break;
8259
8260 case 4:
8261 //flip v
8262 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8263 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8264 break;
8265
8266 case 5:
8267 //trans + v flip
8268 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8269 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8270 break;
8271
8272 case 6:
8273 //pivot + v flip
8274 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8275 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8276 break;
8277
8278 case 8:
8279 //vlip h
8280 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8281 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8282 break;
8283
8284 case 9:
8285 //trans + h flip
8286 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8287 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8288 break;
8289
8290 case 10:
8291 //flip H and pivot
8292 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8293 //return error cannot pivot and h flip
8294 break;
8295
8296 case 12:
8297 //vh flip
8298 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8299 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8300 break;
8301
8302 case 13:
8303 //trans + vh flip
8304 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8305 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8306 break;
8307
8308 case 14:
8309 //pivot and vh flip
8310 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8311 //return error cannot both pivot and vh flip
8312 break;
8313
8314 case 16:
8315 //lit
8316 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8317 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8318 break;
8319
8320 case 18:
8321 //pivot, lit
8322 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8323 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8324 break;
8325
8326 case 20:
8327 //lit + v flip
8328 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8329 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8330 break;
8331
8332 case 22:
8333 //Pivot, vflip, lit
8334 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8335 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8336 break;
8337
8338 case 24:
8339 //lit + h flip
8340 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8341 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8342 break;
8343
8344 case 26:
8345 //pivot + lit + hflip
8346 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8347 //return error cannot pivot, lit, and flip
8348 break;
8349
8350 case 28:
8351 //lit + vh flip
8352 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8353 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8354 break;
8355
8356 case 32: //gouraud
8357 //Probably not wort supporting.
8358 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8359 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8360 break;
8361
8362 case 0:
8363 //no effect
8364 stretch_blit(newSource, newDest, sx, sy, sw, sh, dx, dy, dw, dh);
8365 break;
8366
8367
8368 default:
8369 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8370
8371
8372 }
8373 } //end if not rotated
8374
8375 if ( rot != 0 ) //if rotated
8376 {
8377 switch(mode)
8378 {
8379 case 1:
8380 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8381 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8382
8383 break;
8384
8385 case 2:
8386 //pivot?
8387 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8388 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8389 //Pivoting requires two more args
8390 break;
8391
8392 case 3:
8393 //pivot + trans
8394 //return an error, cannot both rotate and pivot
8395 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8396 break;
8397
8398 case 4:
8399 //flip v
8400 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8401 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8402 break;
8403
8404 case 5:
8405 //trans + v flip
8406 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8407 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8408 break;
8409
8410 case 6:
8411 //pivot + v flip
8412 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8413 //return an error, cannot both rotate and pivot
8414 break;
8415
8416 case 8:
8417 //flip h
8418 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8419 //return an error, cannot both rotate and flip H
8420 break;
8421
8422 case 9:
8423 //trans + h flip
8424 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8425 //return an error, cannot rotate and flip a trans sprite
8426 break;
8427
8428 case 10:
8429 //flip H and pivot
8430 //return error cannot pivot and h flip
8431 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8432 break;
8433
8434 case 12:
8435 //vh flip
8436 //return an error, cannot rotate and VH flip a trans sprite
8437 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8438 break;
8439
8440 case 13:
8441 //trans + vh flip
8442 //return an error, cannot rotate and VH flip a trans sprite
8443 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8444 break;
8445
8446 case 14:
8447 //pivot and vh flip
8448 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8449 //return error cannot both pivot and vh flip
8450 break;
8451
8452 case 16:
8453 //lit
8454 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8455 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8456 break;
8457
8458 case 18:
8459 //pivot, lit
8460 //return an error, cannot both rotate and pivot
8461 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8462 break;
8463
8464 case 20:
8465 //lit + vflip
8466 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
8467 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8468 break;
8469
8470 case 22:
8471 //Pivot, vflip, lit
8472 //return an error, cannot both rotate and pivot
8473 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8474 break;
8475
8476 case 24:
8477 //lit + h flip
8478 //return an error, cannot both rotate and H flip
8479 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8480 break;
8481
8482 case 26:
8483 //pivot + lit + hflip
8484 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8485 //return error cannot pivot, lit, and flip
8486 break;
8487
8488 case 28:
8489 //lit + vh flip
8490 //return an error, cannot both rotate and VH flip
8491 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8492 break;
8493
8494 case 32: //gouraud
8495 //Probably not wort supporting.
8496 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8497 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8498 break;
8499
8500 case 0:
8501 //no effect.
8502 stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8503 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8504 break;
8505
8506 default:
8507 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8508
8509 }
8510 }
8511
8512 } //end if stretched, but not masked
8513 }
8514 else //not stretched
8515 {
8516
8517
2/2
✓ Branch 0 taken 113326 times.
✓ Branch 1 taken 3 times.
113329 if(masked) //if masked, but not stretched
8518 {
8519
8520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113326 times.
113326 if ( rot == 0 ) //if not rotated
8521 {
8522
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 113326 times.
113326 switch(mode)
8523 {
8524 case 1:
8525 //transparent
8526 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8527 draw_trans_sprite(newDest, subBmp, dx, dy);
8528 break;
8529
8530
8531 case 2:
8532 //pivot?
8533 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8534 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8535 //Pivoting requires two more args
8536 break;
8537
8538 case 3:
8539 //pivot + trans
8540 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8541 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8542 break;
8543
8544 case 4:
8545 //flip v
8546 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8547 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8548 break;
8549
8550 case 5:
8551 //trans + v flip
8552 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8553 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8554 break;
8555
8556 case 6:
8557 //pivot + v flip
8558 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8559 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8560 break;
8561
8562 case 8:
8563 //vlip h
8564 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8565 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8566 break;
8567
8568 case 9:
8569 //trans + h flip
8570 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8571 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8572 break;
8573
8574 case 10:
8575 //flip H and pivot
8576 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8577 //return error cannot pivot and h flip
8578 break;
8579
8580 case 12:
8581 //vh flip
8582 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8583 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8584 break;
8585
8586 case 13:
8587 //trans + vh flip
8588 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8589 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8590 break;
8591
8592 case 14:
8593 //pivot and vh flip
8594 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8595 //return error cannot both pivot and vh flip
8596 break;
8597
8598 case 16:
8599 //lit
8600 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8601 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8602 break;
8603
8604 case 18:
8605 //pivot, lit
8606 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8607 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8608 break;
8609
8610 case 20:
8611 //lit + v flip
8612 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8613 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8614 break;
8615
8616 case 22:
8617 //Pivot, vflip, lit
8618 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8619 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8620 break;
8621
8622 case 24:
8623 //lit + h flip
8624 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8625 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8626 break;
8627
8628 case 26:
8629 //pivot + lit + hflip
8630 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8631 //return error cannot pivot, lit, and flip
8632 break;
8633
8634 case 28:
8635 //lit + vh flip
8636 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8637 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8638 break;
8639
8640 case 32: //gouraud
8641 //Probably not wort supporting.
8642 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8643 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8644 break;
8645
8646 case 0:
8647 //no effect
8648 113326 masked_blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8649 113326 break;
8650
8651
8652 default:
8653 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8654
8655
8656 }
8657 113326 } //end if not rotated
8658
8659
1/2
✓ Branch 0 taken 113326 times.
✗ Branch 1 not taken.
113326 if ( rot != 0 ) //if rotated
8660 {
8661 switch(mode)
8662 {
8663 case 1:
8664 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //transparent
8665 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8666
8667 break;
8668
8669 case 2:
8670 //pivot?
8671 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8672 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8673 //Pivoting requires two more args
8674 break;
8675
8676 case 3:
8677 //pivot + trans
8678 //return an error, cannot both rotate and pivot
8679 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8680 break;
8681
8682 case 4:
8683 //flip v
8684 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8685 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8686 break;
8687
8688 case 5:
8689 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
8690 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8691 break;
8692
8693 case 6:
8694 //pivot + v flip
8695 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8696 //return an error, cannot both rotate and pivot
8697 break;
8698
8699 case 8:
8700 //flip h
8701 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8702 //return an error, cannot both rotate and flip H
8703 break;
8704
8705 case 9:
8706 //trans + h flip
8707 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8708 //return an error, cannot rotate and flip a trans sprite
8709 break;
8710
8711 case 10:
8712 //flip H and pivot
8713 //return error cannot pivot and h flip
8714 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8715 break;
8716
8717 case 12:
8718 //vh flip
8719 //return an error, cannot rotate and VH flip a trans sprite
8720 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8721 break;
8722
8723 case 13:
8724 //trans + vh flip
8725 //return an error, cannot rotate and VH flip a trans sprite
8726 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
8727 break;
8728
8729 case 14:
8730 //pivot and vh flip
8731 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8732 //return error cannot both pivot and vh flip
8733 break;
8734
8735 case 16:
8736 //lit
8737 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8738 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8739 break;
8740
8741 case 18:
8742 //pivot, lit
8743 //return an error, cannot both rotate and pivot
8744 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8745 break;
8746
8747 case 20:
8748 //lit + vflip
8749 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8750 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
8751 break;
8752
8753 case 22:
8754 //Pivot, vflip, lit
8755 //return an error, cannot both rotate and pivot
8756 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
8757 break;
8758
8759 case 24:
8760 //lit + h flip
8761 //return an error, cannot both rotate and H flip
8762 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
8763 break;
8764
8765 case 26:
8766 //pivot + lit + hflip
8767 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
8768 //return error cannot pivot, lit, and flip
8769 break;
8770
8771 case 28:
8772 //lit + vh flip
8773 //return an error, cannot both rotate and VH flip
8774 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8775 break;
8776
8777 case 32: //gouraud
8778 //Probably not wort supporting.
8779 //stretch_blit(newSource, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
8780 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8781 break;
8782
8783 case 0:
8784 //no effect.
8785 masked_blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8786 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8787 break;
8788
8789 default:
8790 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8791
8792 }
8793 } //end rtated, masked
8794 113326 } //end if masked
8795
8796 else //not masked, and not stretched; just blit
8797 {
8798
8799
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if ( rot == 0 ) //if not rotated
8800 {
8801
1/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✓ Branch 21 taken 3 times.
3 switch(mode)
8802 {
8803 case 1:
8804 //transparent
8805 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8806 draw_trans_sprite(newDest, subBmp, dx, dy);
8807 break;
8808
8809
8810 case 2:
8811 //pivot?
8812 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8813 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8814 //Pivoting requires two more args
8815 break;
8816
8817 case 3:
8818 //pivot + trans
8819 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8820 pivot_sprite_trans(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8821 break;
8822
8823 case 4:
8824 //flip v
8825 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8826 draw_sprite_v_flip(newDest, subBmp, dx, dy);
8827 break;
8828
8829 case 5:
8830 //trans + v flip
8831 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8832 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
8833 break;
8834
8835 case 6:
8836 //pivot + v flip
8837 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8838 pivot_sprite_v_flip(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8839 break;
8840
8841 case 8:
8842 //vlip h
8843 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8844 draw_sprite_h_flip(newDest, subBmp, dx, dy);
8845 break;
8846
8847 case 9:
8848 //trans + h flip
8849 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8850 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
8851 break;
8852
8853 case 10:
8854 //flip H and pivot
8855 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8856 //return error cannot pivot and h flip
8857 break;
8858
8859 case 12:
8860 //vh flip
8861 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8862 draw_sprite_vh_flip(newDest, subBmp, dx, dy);
8863 break;
8864
8865 case 13:
8866 //trans + vh flip
8867 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8868 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
8869 break;
8870
8871 case 14:
8872 //pivot and vh flip
8873 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
8874 //return error cannot both pivot and vh flip
8875 break;
8876
8877 case 16:
8878 //lit
8879 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8880 draw_lit_sprite(newDest, subBmp, dx, dy, litcolour);
8881 break;
8882
8883 case 18:
8884 //pivot, lit
8885 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8886 pivot_sprite_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8887 break;
8888
8889 case 20:
8890 //lit + v flip
8891 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8892 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
8893 break;
8894
8895 case 22:
8896 //Pivot, vflip, lit
8897 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8898 pivot_sprite_v_flip_lit(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
8899 break;
8900
8901 case 24:
8902 //lit + h flip
8903 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8904 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
8905 break;
8906
8907 case 26:
8908 //pivot + lit + hflip
8909 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot, Flip, and Lit.\n", bitmapIndex);
8910 //return error cannot pivot, lit, and flip
8911 break;
8912
8913 case 28:
8914 //lit + vh flip
8915 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8916 draw_sprite_ex(newDest, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
8917 break;
8918
8919 case 32: //gouraud
8920 //Probably not wort supporting.
8921 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8922 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
8923 break;
8924
8925 case 0:
8926 //no effect
8927 3 blit(newSource, newDest, sx, sy, dx, dy, dw, dh);
8928 3 break;
8929
8930
8931 default:
8932 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
8933
8934
8935 }
8936 3 } //end if not rotated
8937
8938
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if ( rot != 0 ) //if rotated
8939 {
8940 switch(mode)
8941 {
8942 case 1:
8943 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);//transparent
8944 rotate_sprite_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8945
8946 break;
8947
8948 case 2:
8949 //pivot?
8950 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8951 pivot_sprite(newDest, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
8952 //Pivoting requires two more args
8953 break;
8954
8955 case 3:
8956 //pivot + trans
8957 //return an error, cannot both rotate and pivot
8958 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8959 break;
8960
8961 case 4:
8962 //flip v
8963 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8964 rotate_sprite_v_flip(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8965 break;
8966
8967 case 5:
8968 //trans + v flip
8969 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
8970 rotate_sprite_v_flip_trans(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
8971 break;
8972
8973 case 6:
8974 //pivot + v flip
8975 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
8976 //return an error, cannot both rotate and pivot
8977 break;
8978
8979 case 8:
8980 //flip h
8981 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rorate and H-Flip.\n", bitmapIndex);
8982 //return an error, cannot both rotate and flip H
8983 break;
8984
8985 case 9:
8986 //trans + h flip
8987 Z_message("Warning: Screen->DrawBitmap(%d) cannot Rotate and Flip a Trans Sprite.\n", bitmapIndex);
8988 //return an error, cannot rotate and flip a trans sprite
8989 break;
8990
8991 case 10:
8992 //flip H and pivot
8993 //return error cannot pivot and h flip
8994 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and H-Flip.\n", bitmapIndex);
8995 break;
8996
8997 case 12:
8998 //vh flip
8999 //return an error, cannot rotate and VH flip a trans sprite
9000 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9001 break;
9002
9003 case 13:
9004 //trans + vh flip
9005 //return an error, cannot rotate and VH flip a trans sprite
9006 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and VH-Flip.\n", bitmapIndex);
9007 break;
9008
9009 case 14:
9010 //pivot and vh flip
9011 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9012 //return error cannot both pivot and vh flip
9013 break;
9014
9015 case 16:
9016 //lit
9017 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9018 rotate_sprite_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9019 break;
9020
9021 case 18:
9022 //pivot, lit
9023 //return an error, cannot both rotate and pivot
9024 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rorate.\n", bitmapIndex);
9025 break;
9026
9027 case 20:
9028 //lit + vflip
9029 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9030 rotate_sprite_v_flip_lit(newDest, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9031 break;
9032
9033 case 22:
9034 //Pivot, vflip, lit
9035 //return an error, cannot both rotate and pivot
9036 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Rotate.\n", bitmapIndex);
9037 break;
9038
9039 case 24:
9040 //lit + h flip
9041 //return an error, cannot both rotate and H flip
9042 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Rotate and H-Flip.\n", bitmapIndex);
9043 break;
9044
9045 case 26:
9046 //pivot + lit + hflip
9047 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and Flip a Lit Sprite.\n", bitmapIndex);
9048 //return error cannot pivot, lit, and flip
9049 break;
9050
9051 case 28:
9052 //lit + vh flip
9053 //return an error, cannot both rotate and VH flip
9054 Z_message("Warning: Screen->DrawBitmap(%d) cannot both Pivot and VH-Flip.\n", bitmapIndex);
9055 break;
9056
9057 case 32: //gouraud
9058 //Probably not wort supporting.
9059 //blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9060 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9061 break;
9062
9063 case 0:
9064 //no effect.
9065 blit(newSource, subBmp, sx, sy, 0, 0, dw, dh);
9066 rotate_sprite(newDest, subBmp, dx, dy, degrees_to_fixed(rot));
9067 break;
9068
9069 default:
9070 return Z_message("Warning: Screen->DrawBitmap(%d) mode flags not possible in this combination!\n", bitmapIndex);
9071
9072 }
9073 } //end if rotated
9074 } //end if not masked
9075 } //end if not stretched
9076
9077 //cleanup
9078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 113329 times.
113329 if(subBmp)
9079 {
9080 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
9081 destroy_bitmap(subBmp);
9082 }
9083
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 113326 times.
113329 if(newSource != destBMP)
9084 {
9085 3 destroy_bitmap(newSource);
9086 3 }
9087 113329 }
9088
9089 void do_tileblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp, char const* funcstr)
9090 {
9091 /*
9092 //sdci[1]=layer
9093 //sdci[2]=tile
9094 //sdci[3]=cset
9095 //sdci[4]=sourcex
9096 //sdci[5]=sourcey
9097 //sdci[6]=sourcew
9098 //sdci[7]=sourceh
9099 //sdci[8]=destx
9100 //sdci[9]=desty
9101 //sdci[10]=destw
9102 //sdci[11]=desth
9103 //sdci[12]=rotation/angle
9104 //scdi[13] = pivot cx
9105 //sdci[14] = pivot cy
9106 //scdi[15] = effect flags
9107
9108 // ZScript-side constant values:
9109 const int32_t BITDX_NORMAL = 0;
9110 const int32_t BITDX_TRANS = 1; //Translucent
9111 const int32_t BITDX_PIVOT = 2; //THe sprite will rotate at a specific point, instead of its center.
9112 const int32_t BITDX_HFLIP = 4; //Horizontal Flip
9113 const int32_t BITDX_VFLIP = 8; //Vertical Flip.
9114 //Note: Some modes cannot be combined. if a combination is not supported, an error
9115 // detailing this will be shown in allegro.log.
9116
9117 //scdi[16] = litcolour
9118 //The allegro docs are wrong. The params are: rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9119 //not rotate_sprite_lit(bmp, subBmp, dx, dy, degrees_to_fixed(rot));
9120
9121 //sdci[17]=mask
9122 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
9123
9124 */
9125
9126 int32_t tile = sdci[2]/10000;
9127 int32_t cset = WRAP_CS(sdci[3]/10000);
9128
9129 int32_t sx = sdci[4]/10000;
9130 int32_t sy = sdci[5]/10000;
9131 int32_t sw = sdci[6]/10000;
9132 //Z_scripterrlog("sh is: %d\n",sdci[5]/10000);
9133 int32_t sh = sdci[7]/10000;
9134 //Z_scripterrlog("sh is: %d\n",sdci[6]/10000);
9135 int32_t dx = sdci[8]/10000;
9136 int32_t dy = sdci[9]/10000;
9137 int32_t dw = sdci[10]/10000;
9138 int32_t dh = sdci[11]/10000;
9139 float rot = sdci[12]/10000;
9140 int32_t cx = sdci[13]/10000;
9141 int32_t cy = sdci[14]/10000;
9142 int32_t mode = sdci[15]/10000;
9143 int32_t litcolour = sdci[16]/10000;
9144 bool masked = (sdci[17] != 0);
9145
9146 int32_t ref = 0;
9147
9148 if ( is_bmp && (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
9149 //Do we need to also check the render target and do the same thing if the
9150 //dest == -2 and the render target is not RT_SCREEN?
9151 dx += xoffset;
9152 dy += yoffset;
9153
9154 BITMAP *destbmp = nullptr;
9155 if(is_bmp)
9156 {
9157 ref = sdci[DRAWCMD_BMP_TARGET];
9158
9159 if ( ref <= 0 )
9160 {
9161 Z_scripterrlog("%s wanted to use to an invalid dest bitmap id: %d. Aborting.\n", funcstr, ref);
9162 return;
9163 }
9164 destbmp = FFCore.GetScriptBitmap(ref);
9165 if(!destbmp)
9166 {
9167 Z_message("Warning: %s dest bitmap %d contains invalid data or is not initialized.\n", ref);
9168 Z_message("[Note* Deferred drawing or layering order possibly not set right.]\n");
9169 return;
9170 }
9171 }
9172 else destbmp = bmp;
9173
9174 bool stretched = (sw != dw || sh != dh);
9175
9176 BITMAP* srcbmp = create_bitmap_ex(8, sw, sh);
9177 //Draw tiles to srcbmp
9178 {
9179 clear_bitmap(srcbmp);
9180 int tx = 0, ty = 0;
9181 if(sx < 0)
9182 tx = (sx-15)/16;
9183 else if(sx > 15)
9184 tx = sx/16;
9185 if(sy < 0)
9186 ty = (sy-15)/16;
9187 else if(sy > 15)
9188 ty = sy/16;
9189
9190 int gxoff = -wrap(sx,0,15), gyoff = -wrap(sy,0,15);
9191 for(int ix = 0; ix <= sw; ix += 16)
9192 {
9193 for(int iy = 0; iy <= sh; iy += 16)
9194 {
9195 int t = tile+(tx+ix/16);
9196 int rowdiff = TILEROW(t) - TILEROW(tile);
9197 t += rowdiff * (sh/16) * TILES_PER_ROW;
9198 t += (ty+iy/16)*TILES_PER_ROW;
9199 overtile16(srcbmp, t, ix+gxoff, iy+gyoff, cset, 0);
9200 }
9201 }
9202
9203 sx = sy = 0;
9204 }
9205
9206 BITMAP* subBmp = nullptr;
9207
9208 if(rot != 0 || mode != 0)
9209 {
9210 subBmp = create_bitmap_ex(8,destbmp->w, destbmp->h);//script_drawing_commands.AquireSubBitmap(dw, dh);
9211 clear_bitmap(subBmp);
9212
9213 if(!subBmp)
9214 {
9215 Z_scripterrlog("%s failed to create a sub-bitmap to use for %s. Aborting.\n", funcstr, "rotation");
9216 return;
9217 }
9218 }
9219
9220 //dx = dx + xoffset; //don't do this here!
9221 //dy = dy + yoffset; //Nor this. It auto-offsets the bitmap by +56. Hmm. The fix that gleeok made isn't being applied to these functions. -Z ( 17th April, 2019 )
9222
9223 if(stretched)
9224 {
9225 if(masked)
9226 { //stretched and masked
9227 if ( rot == 0 )
9228 { //if not rotated
9229 switch(mode)
9230 {
9231 case 1:
9232 //transparent
9233 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9234 draw_trans_sprite(destbmp, subBmp, dx, dy);
9235 break;
9236
9237
9238 case 2:
9239 //pivot?
9240 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9241 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9242 //Pivoting requires two more args
9243 break;
9244
9245 case 3:
9246 //pivot + trans
9247 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9248 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9249 break;
9250
9251 case 4:
9252 //flip v
9253 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9254 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9255 break;
9256
9257 case 5:
9258 //trans + v flip
9259 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9260 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9261 break;
9262
9263 case 6:
9264 //pivot + v flip
9265 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9266 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9267 break;
9268
9269 case 8:
9270 //vlip h
9271 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9272 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9273 break;
9274
9275 case 9:
9276 //trans + h flip
9277 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9278 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9279 break;
9280
9281 case 10:
9282 //flip H and pivot
9283 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9284 //return error cannot pivot and h flip
9285 break;
9286
9287 case 12:
9288 //vh flip
9289 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9290 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9291 break;
9292
9293 case 13:
9294 //trans + vh flip
9295 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9296 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9297 break;
9298
9299 case 14:
9300 //pivot and vh flip
9301 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9302 //return error cannot both pivot and vh flip
9303 break;
9304
9305 case 16:
9306 //lit
9307 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9308 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9309 break;
9310
9311 case 18:
9312 //pivot, lit
9313 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9314 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9315 break;
9316
9317 case 20:
9318 //lit + v flip
9319 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9320 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9321 break;
9322
9323 case 22:
9324 //Pivot, vflip, lit
9325 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9326 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9327 break;
9328
9329 case 24:
9330 //lit + h flip
9331 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9332 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9333 break;
9334
9335 case 26:
9336 //pivot + lit + hflip
9337 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9338 //return error cannot pivot, lit, and flip
9339 break;
9340
9341 case 28:
9342 //lit + vh flip
9343 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9344 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9345 break;
9346
9347 case 32: //gouraud
9348 //Probably not wort supporting.
9349 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9350 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9351 break;
9352
9353 case 0:
9354 //no effect
9355 masked_stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9356 break;
9357
9358
9359 default:
9360 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9361
9362
9363 }
9364 } //end if not rotated
9365
9366 if ( rot != 0 ) //if rotated
9367 {
9368 switch(mode)
9369 {
9370 case 1:
9371 //transparent
9372 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9373 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9374
9375 break;
9376
9377 case 2:
9378 //pivot?
9379 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9380 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9381 //Pivoting requires two more args
9382 break;
9383
9384 case 3:
9385 //pivot + trans
9386 //return an error, cannot both rotate and pivot
9387 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9388 break;
9389
9390 case 4:
9391 //flip v
9392 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9393 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9394 break;
9395
9396 case 5:
9397 //trans + v flip
9398 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9399 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9400 break;
9401
9402 case 6:
9403 //pivot + v flip
9404 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9405 //return an error, cannot both rotate and pivot
9406 break;
9407
9408 case 8:
9409 //flip h
9410 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9411 //return an error, cannot both rotate and flip H
9412 break;
9413
9414 case 9:
9415 //trans + h flip
9416 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9417 //return an error, cannot rotate and flip a trans sprite
9418 break;
9419
9420 case 10:
9421 //flip H and pivot
9422 //return error cannot pivot and h flip
9423 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9424 break;
9425
9426 case 12:
9427 //vh flip
9428 //return an error, cannot rotate and VH flip a trans sprite
9429 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9430 break;
9431
9432 case 13:
9433 //trans + vh flip
9434 //return an error, cannot rotate and VH flip a trans sprite
9435 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9436 break;
9437
9438 case 14:
9439 //pivot and vh flip
9440 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9441 //return error cannot both pivot and vh flip
9442 break;
9443
9444 case 16:
9445 //lit
9446 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9447 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9448 break;
9449
9450 case 18:
9451 //pivot, lit
9452 //return an error, cannot both rotate and pivot
9453 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9454 break;
9455
9456 case 20:
9457 //lit + vflip
9458 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9459 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9460 break;
9461
9462 case 22:
9463 //Pivot, vflip, lit
9464 //return an error, cannot both rotate and pivot
9465 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9466 break;
9467
9468 case 24:
9469 //lit + h flip
9470 //return an error, cannot both rotate and H flip
9471 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9472 break;
9473
9474 case 26:
9475 //pivot + lit + hflip
9476 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9477 //return error cannot pivot, lit, and flip
9478 break;
9479
9480 case 28:
9481 //lit + vh flip
9482 //return an error, cannot both rotate and VH flip
9483 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9484 break;
9485
9486 case 32: //gouraud
9487 //Probably not wort supporting.
9488 //masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9489 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9490 break;
9491
9492 case 0:
9493 //no effect.
9494 masked_stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9495 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9496 break;
9497
9498 default:
9499 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9500
9501 }
9502 }
9503 } //end if stretched and masked
9504
9505 else //stretched, not masked
9506 {
9507
9508
9509 if ( rot == 0 ) //if not rotated
9510 {
9511 switch(mode)
9512 {
9513 case 1:
9514 //transparent
9515 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9516 draw_trans_sprite(destbmp, subBmp, dx, dy);
9517 break;
9518
9519
9520 case 2:
9521 //pivot?
9522 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9523 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9524 //Pivoting requires two more args
9525 break;
9526
9527 case 3:
9528 //pivot + trans
9529 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9530 pivot_sprite_trans(destbmp, subBmp, dx,dy, cx, cy, degrees_to_fixed(rot));
9531 break;
9532
9533 case 4:
9534 //flip v
9535 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9536 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9537 break;
9538
9539 case 5:
9540 //trans + v flip
9541 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9542 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9543 break;
9544
9545 case 6:
9546 //pivot + v flip
9547 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9548 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9549 break;
9550
9551 case 8:
9552 //vlip h
9553 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9554 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9555 break;
9556
9557 case 9:
9558 //trans + h flip
9559 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9560 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9561 break;
9562
9563 case 10:
9564 //flip H and pivot
9565 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9566 //return error cannot pivot and h flip
9567 break;
9568
9569 case 12:
9570 //vh flip
9571 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9572 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9573 break;
9574
9575 case 13:
9576 //trans + vh flip
9577 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9578 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9579 break;
9580
9581 case 14:
9582 //pivot and vh flip
9583 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9584 //return error cannot both pivot and vh flip
9585 break;
9586
9587 case 16:
9588 //lit
9589 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9590 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9591 break;
9592
9593 case 18:
9594 //pivot, lit
9595 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9596 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9597 break;
9598
9599 case 20:
9600 //lit + v flip
9601 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9602 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9603 break;
9604
9605 case 22:
9606 //Pivot, vflip, lit
9607 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9608 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9609 break;
9610
9611 case 24:
9612 //lit + h flip
9613 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9614 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9615 break;
9616
9617 case 26:
9618 //pivot + lit + hflip
9619 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9620 //return error cannot pivot, lit, and flip
9621 break;
9622
9623 case 28:
9624 //lit + vh flip
9625 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9626 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9627 break;
9628
9629 case 32: //gouraud
9630 //Probably not wort supporting.
9631 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9632 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9633 break;
9634
9635 case 0:
9636 //no effect
9637 stretch_blit(srcbmp, destbmp, sx, sy, sw, sh, dx, dy, dw, dh);
9638 break;
9639
9640
9641 default:
9642 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9643
9644
9645 }
9646 } //end if not rotated
9647
9648 if ( rot != 0 ) //if rotated
9649 {
9650 switch(mode)
9651 {
9652 case 1:
9653 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9654 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9655
9656 break;
9657
9658 case 2:
9659 //pivot?
9660 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9661 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9662 //Pivoting requires two more args
9663 break;
9664
9665 case 3:
9666 //pivot + trans
9667 //return an error, cannot both rotate and pivot
9668 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9669 break;
9670
9671 case 4:
9672 //flip v
9673 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9674 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9675 break;
9676
9677 case 5:
9678 //trans + v flip
9679 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9680 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9681 break;
9682
9683 case 6:
9684 //pivot + v flip
9685 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9686 //return an error, cannot both rotate and pivot
9687 break;
9688
9689 case 8:
9690 //flip h
9691 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9692 //return an error, cannot both rotate and flip H
9693 break;
9694
9695 case 9:
9696 //trans + h flip
9697 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9698 //return an error, cannot rotate and flip a trans sprite
9699 break;
9700
9701 case 10:
9702 //flip H and pivot
9703 //return error cannot pivot and h flip
9704 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9705 break;
9706
9707 case 12:
9708 //vh flip
9709 //return an error, cannot rotate and VH flip a trans sprite
9710 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9711 break;
9712
9713 case 13:
9714 //trans + vh flip
9715 //return an error, cannot rotate and VH flip a trans sprite
9716 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9717 break;
9718
9719 case 14:
9720 //pivot and vh flip
9721 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9722 //return error cannot both pivot and vh flip
9723 break;
9724
9725 case 16:
9726 //lit
9727 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9728 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9729 break;
9730
9731 case 18:
9732 //pivot, lit
9733 //return an error, cannot both rotate and pivot
9734 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9735 break;
9736
9737 case 20:
9738 //lit + vflip
9739 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);//transparent
9740 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
9741 break;
9742
9743 case 22:
9744 //Pivot, vflip, lit
9745 //return an error, cannot both rotate and pivot
9746 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9747 break;
9748
9749 case 24:
9750 //lit + h flip
9751 //return an error, cannot both rotate and H flip
9752 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9753 break;
9754
9755 case 26:
9756 //pivot + lit + hflip
9757 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
9758 //return error cannot pivot, lit, and flip
9759 break;
9760
9761 case 28:
9762 //lit + vh flip
9763 //return an error, cannot both rotate and VH flip
9764 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9765 break;
9766
9767 case 32: //gouraud
9768 //Probably not wort supporting.
9769 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9770 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9771 break;
9772
9773 case 0:
9774 //no effect.
9775 stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9776 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9777 break;
9778
9779 default:
9780 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9781
9782 }
9783 }
9784
9785 } //end if stretched, but not masked
9786 }
9787 else //not stretched
9788 {
9789
9790 if(masked) //if masked, but not stretched
9791 {
9792
9793 if ( rot == 0 ) //if not rotated
9794 {
9795 switch(mode)
9796 {
9797 case 1:
9798 //transparent
9799 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9800 draw_trans_sprite(destbmp, subBmp, dx, dy);
9801 break;
9802
9803
9804 case 2:
9805 //pivot?
9806 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9807 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9808 //Pivoting requires two more args
9809 break;
9810
9811 case 3:
9812 //pivot + trans
9813 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9814 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9815 break;
9816
9817 case 4:
9818 //flip v
9819 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9820 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
9821 break;
9822
9823 case 5:
9824 //trans + v flip
9825 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9826 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
9827 break;
9828
9829 case 6:
9830 //pivot + v flip
9831 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9832 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9833 break;
9834
9835 case 8:
9836 //vlip h
9837 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9838 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
9839 break;
9840
9841 case 9:
9842 //trans + h flip
9843 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9844 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
9845 break;
9846
9847 case 10:
9848 //flip H and pivot
9849 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9850 //return error cannot pivot and h flip
9851 break;
9852
9853 case 12:
9854 //vh flip
9855 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9856 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
9857 break;
9858
9859 case 13:
9860 //trans + vh flip
9861 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9862 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
9863 break;
9864
9865 case 14:
9866 //pivot and vh flip
9867 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
9868 //return error cannot both pivot and vh flip
9869 break;
9870
9871 case 16:
9872 //lit
9873 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9874 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
9875 break;
9876
9877 case 18:
9878 //pivot, lit
9879 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9880 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9881 break;
9882
9883 case 20:
9884 //lit + v flip
9885 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9886 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
9887 break;
9888
9889 case 22:
9890 //Pivot, vflip, lit
9891 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9892 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
9893 break;
9894
9895 case 24:
9896 //lit + h flip
9897 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9898 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
9899 break;
9900
9901 case 26:
9902 //pivot + lit + hflip
9903 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
9904 //return error cannot pivot, lit, and flip
9905 break;
9906
9907 case 28:
9908 //lit + vh flip
9909 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9910 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
9911 break;
9912
9913 case 32: //gouraud
9914 //Probably not wort supporting.
9915 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
9916 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
9917 break;
9918
9919 case 0:
9920 //no effect
9921 masked_blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
9922 break;
9923
9924
9925 default:
9926 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
9927
9928
9929 }
9930 } //end if not rotated
9931
9932 if ( rot != 0 ) //if rotated
9933 {
9934 switch(mode)
9935 {
9936 case 1:
9937 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //transparent
9938 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9939
9940 break;
9941
9942 case 2:
9943 //pivot?
9944 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9945 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
9946 //Pivoting requires two more args
9947 break;
9948
9949 case 3:
9950 //pivot + trans
9951 //return an error, cannot both rotate and pivot
9952 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9953 break;
9954
9955 case 4:
9956 //flip v
9957 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
9958 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9959 break;
9960
9961 case 5:
9962 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh); //trans + v flip
9963 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
9964 break;
9965
9966 case 6:
9967 //pivot + v flip
9968 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
9969 //return an error, cannot both rotate and pivot
9970 break;
9971
9972 case 8:
9973 //flip h
9974 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
9975 //return an error, cannot both rotate and flip H
9976 break;
9977
9978 case 9:
9979 //trans + h flip
9980 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
9981 //return an error, cannot rotate and flip a trans sprite
9982 break;
9983
9984 case 10:
9985 //flip H and pivot
9986 //return error cannot pivot and h flip
9987 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
9988 break;
9989
9990 case 12:
9991 //vh flip
9992 //return an error, cannot rotate and VH flip a trans sprite
9993 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
9994 break;
9995
9996 case 13:
9997 //trans + vh flip
9998 //return an error, cannot rotate and VH flip a trans sprite
9999 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10000 break;
10001
10002 case 14:
10003 //pivot and vh flip
10004 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10005 //return error cannot both pivot and vh flip
10006 break;
10007
10008 case 16:
10009 //lit
10010 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10011 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10012 break;
10013
10014 case 18:
10015 //pivot, lit
10016 //return an error, cannot both rotate and pivot
10017 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10018 break;
10019
10020 case 20:
10021 //lit + vflip
10022 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10023 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10024 break;
10025
10026 case 22:
10027 //Pivot, vflip, lit
10028 //return an error, cannot both rotate and pivot
10029 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10030 break;
10031
10032 case 24:
10033 //lit + h flip
10034 //return an error, cannot both rotate and H flip
10035 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10036 break;
10037
10038 case 26:
10039 //pivot + lit + hflip
10040 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10041 //return error cannot pivot, lit, and flip
10042 break;
10043
10044 case 28:
10045 //lit + vh flip
10046 //return an error, cannot both rotate and VH flip
10047 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10048 break;
10049
10050 case 32: //gouraud
10051 //Probably not wort supporting.
10052 //stretch_blit(srcbmp, subBmp, sx, sy, sw, sh, 0, 0, dw, dh);
10053 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10054 break;
10055
10056 case 0:
10057 //no effect.
10058 masked_blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10059 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10060 break;
10061
10062 default:
10063 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10064
10065 }
10066 } //end rtated, masked
10067 } //end if masked
10068
10069 else //not masked, and not stretched; just blit
10070 {
10071
10072 if ( rot == 0 ) //if not rotated
10073 {
10074 switch(mode)
10075 {
10076 case 1:
10077 //transparent
10078 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10079 draw_trans_sprite(destbmp, subBmp, dx, dy);
10080 break;
10081
10082
10083 case 2:
10084 //pivot?
10085 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10086 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10087 //Pivoting requires two more args
10088 break;
10089
10090 case 3:
10091 //pivot + trans
10092 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10093 pivot_sprite_trans(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10094 break;
10095
10096 case 4:
10097 //flip v
10098 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10099 draw_sprite_v_flip(destbmp, subBmp, dx, dy);
10100 break;
10101
10102 case 5:
10103 //trans + v flip
10104 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10105 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_V_FLIP);
10106 break;
10107
10108 case 6:
10109 //pivot + v flip
10110 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10111 pivot_sprite_v_flip(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10112 break;
10113
10114 case 8:
10115 //vlip h
10116 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10117 draw_sprite_h_flip(destbmp, subBmp, dx, dy);
10118 break;
10119
10120 case 9:
10121 //trans + h flip
10122 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10123 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_H_FLIP);
10124 break;
10125
10126 case 10:
10127 //flip H and pivot
10128 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10129 //return error cannot pivot and h flip
10130 break;
10131
10132 case 12:
10133 //vh flip
10134 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10135 draw_sprite_vh_flip(destbmp, subBmp, dx, dy);
10136 break;
10137
10138 case 13:
10139 //trans + vh flip
10140 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10141 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_TRANS, DRAW_SPRITE_VH_FLIP);
10142 break;
10143
10144 case 14:
10145 //pivot and vh flip
10146 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10147 //return error cannot both pivot and vh flip
10148 break;
10149
10150 case 16:
10151 //lit
10152 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10153 draw_lit_sprite(destbmp, subBmp, dx, dy, litcolour);
10154 break;
10155
10156 case 18:
10157 //pivot, lit
10158 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10159 pivot_sprite_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10160 break;
10161
10162 case 20:
10163 //lit + v flip
10164 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10165 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_V_FLIP);
10166 break;
10167
10168 case 22:
10169 //Pivot, vflip, lit
10170 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10171 pivot_sprite_v_flip_lit(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot),litcolour);
10172 break;
10173
10174 case 24:
10175 //lit + h flip
10176 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10177 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_H_FLIP);
10178 break;
10179
10180 case 26:
10181 //pivot + lit + hflip
10182 Z_message("Warning: %s cannot both Pivot, Flip, and Lit.\n", funcstr);
10183 //return error cannot pivot, lit, and flip
10184 break;
10185
10186 case 28:
10187 //lit + vh flip
10188 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10189 draw_sprite_ex(destbmp, subBmp, dx, dy, DRAW_SPRITE_LIT, DRAW_SPRITE_VH_FLIP);
10190 break;
10191
10192 case 32: //gouraud
10193 //Probably not wort supporting.
10194 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10195 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10196 break;
10197
10198 case 0:
10199 //no effect
10200 blit(srcbmp, destbmp, sx, sy, dx, dy, dw, dh);
10201 break;
10202
10203
10204 default:
10205 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10206
10207
10208 }
10209 } //end if not rotated
10210
10211 if ( rot != 0 ) //if rotated
10212 {
10213 switch(mode)
10214 {
10215 case 1:
10216 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);//transparent
10217 rotate_sprite_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10218
10219 break;
10220
10221 case 2:
10222 //pivot?
10223 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10224 pivot_sprite(destbmp, subBmp, dx, dy, cx, cy, degrees_to_fixed(rot));
10225 //Pivoting requires two more args
10226 break;
10227
10228 case 3:
10229 //pivot + trans
10230 //return an error, cannot both rotate and pivot
10231 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10232 break;
10233
10234 case 4:
10235 //flip v
10236 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10237 rotate_sprite_v_flip(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10238 break;
10239
10240 case 5:
10241 //trans + v flip
10242 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10243 rotate_sprite_v_flip_trans(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10244 break;
10245
10246 case 6:
10247 //pivot + v flip
10248 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10249 //return an error, cannot both rotate and pivot
10250 break;
10251
10252 case 8:
10253 //flip h
10254 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10255 //return an error, cannot both rotate and flip H
10256 break;
10257
10258 case 9:
10259 //trans + h flip
10260 Z_message("Warning: %s cannot Rotate and Flip a Trans Sprite.\n", funcstr);
10261 //return an error, cannot rotate and flip a trans sprite
10262 break;
10263
10264 case 10:
10265 //flip H and pivot
10266 //return error cannot pivot and h flip
10267 Z_message("Warning: %s cannot both Pivot and H-Flip.\n", funcstr);
10268 break;
10269
10270 case 12:
10271 //vh flip
10272 //return an error, cannot rotate and VH flip a trans sprite
10273 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10274 break;
10275
10276 case 13:
10277 //trans + vh flip
10278 //return an error, cannot rotate and VH flip a trans sprite
10279 Z_message("Warning: %s cannot both Rotate and VH-Flip.\n", funcstr);
10280 break;
10281
10282 case 14:
10283 //pivot and vh flip
10284 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10285 //return error cannot both pivot and vh flip
10286 break;
10287
10288 case 16:
10289 //lit
10290 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10291 rotate_sprite_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10292 break;
10293
10294 case 18:
10295 //pivot, lit
10296 //return an error, cannot both rotate and pivot
10297 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10298 break;
10299
10300 case 20:
10301 //lit + vflip
10302 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10303 rotate_sprite_v_flip_lit(destbmp, subBmp, dx, dy, degrees_to_fixed(rot),litcolour);
10304 break;
10305
10306 case 22:
10307 //Pivot, vflip, lit
10308 //return an error, cannot both rotate and pivot
10309 Z_message("Warning: %s cannot both Pivot and Rotate.\n", funcstr);
10310 break;
10311
10312 case 24:
10313 //lit + h flip
10314 //return an error, cannot both rotate and H flip
10315 Z_message("Warning: %s cannot both Rotate and H-Flip.\n", funcstr);
10316 break;
10317
10318 case 26:
10319 //pivot + lit + hflip
10320 Z_message("Warning: %s cannot both Pivot and Flip a Lit Sprite.\n", funcstr);
10321 //return error cannot pivot, lit, and flip
10322 break;
10323
10324 case 28:
10325 //lit + vh flip
10326 //return an error, cannot both rotate and VH flip
10327 Z_message("Warning: %s cannot both Pivot and VH-Flip.\n", funcstr);
10328 break;
10329
10330 case 32: //gouraud
10331 //Probably not wort supporting.
10332 //blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10333 //draw_gouraud_sprite(BITMAP *bmp, BITMAP *sprite, int32_t x, int32_t y, int32_t c1, int32_t c2, int32_t c3, int32_t c4);
10334 break;
10335
10336 case 0:
10337 //no effect.
10338 blit(srcbmp, subBmp, sx, sy, 0, 0, dw, dh);
10339 rotate_sprite(destbmp, subBmp, dx, dy, degrees_to_fixed(rot));
10340 break;
10341
10342 default:
10343 return Z_message("Warning: %s mode flags not possible in this combination!\n", funcstr);
10344
10345 }
10346 } //end if rotated
10347 } //end if not masked
10348 } //end if not stretched
10349
10350 //cleanup
10351 if(subBmp)
10352 {
10353 //script_drawing_commands.ReleaseSubBitmap(subBmp); //purge the temporary bitmap.
10354 destroy_bitmap(subBmp);
10355 }
10356 destroy_bitmap(srcbmp);
10357 }
10358
10359 void do_comboblit(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool is_bmp)
10360 {
10361 //sdci[2]: combo -> tile
10362 int cid = sdci[2]/10000;
10363 if(unsigned(cid) >= MAXCOMBOS)
10364 {
10365 Z_scripterrlog("ComboBlit tried to draw invalid combo id '%d'\n", cid);
10366 return;
10367 }
10368 sdci[2] = combobuf[cid].tile * 10000;
10369 do_tileblit(bmp, sdci, xoffset, yoffset, is_bmp, "ComboBlit()");
10370 }
10371
10372 void bmp_do_drawquad3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10373 {
10374
10375 //sdci[1]=layer
10376 //sdci[2]=pos[12]
10377 //sdci[3]=uv[8]
10378 //sdci[4]=color[4]
10379 //sdci[5]=size[2]
10380 //sdci[6]=flip
10381 //sdci[7]=tile/combo
10382 //sdci[8]=polytype
10383 //sdci[9] = other bitmap as texture
10384 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10385 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10386 {
10387 Z_scripterrlog("bitmap->Quad3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10388 return;
10389 }
10390 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10391 if ( refbmp == NULL ) return;
10392
10393 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10394
10395 if(!v_ptr)
10396 {
10397 al_trace("Quad3d: Vector pointer is null! Internal error. \n");
10398 return;
10399 }
10400
10401 std::vector<int32_t> &v = *v_ptr;
10402
10403 if(v.empty())
10404 return;
10405
10406 int32_t* pos = &v[0];
10407 int32_t* uv = &v[12];
10408 int32_t* col = &v[20];
10409 int32_t* size = &v[24];
10410
10411 int32_t w = size[0]; //magic numerical constants... yuck.
10412 int32_t h = size[1];
10413 int32_t flip = (sdci[6]/10000)&3;
10414 int32_t tile = sdci[7]/10000;
10415 int32_t polytype = sdci[8]/10000;
10416 int32_t quad_render_source = sdci[9];
10417 Z_scripterrlog("Quad3D texture is %d\n", quad_render_source);
10418
10419 polytype = vbound(polytype, 0, 14);
10420
10421 int32_t tex_width = w*16;
10422 int32_t tex_height = h*16;
10423
10424 bool mustDestroyBmp = false;
10425 BITMAP *tex=NULL;
10426
10427
10428 bool tex_is_bitmap = ( sdci[9] != 0 );
10429 //Z_scripterrlog("sdci[9] is %d\n", quad_render_source);
10430 //Z_scripterrlog("sdci[DRAWCMD_BMP_TARGET] is %d\n", sdci[DRAWCMD_BMP_TARGET]);
10431 BITMAP *bmptexture;
10432
10433 if ( tex_is_bitmap ) bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10434
10435 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10436
10437
10438 if ( !tex_is_bitmap )
10439 {
10440 tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10441
10442 if(!tex)
10443 {
10444 mustDestroyBmp = true;
10445 tex = create_bitmap_ex(8, tex_width, tex_height);
10446 clear_bitmap(tex);
10447 }
10448 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10449 {
10450 Z_message("Quad3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10451 return; //non power of two error
10452 }
10453 if(tile > 0) // TILE
10454 {
10455 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10456 }
10457 else // COMBO
10458 {
10459 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
10460 const int32_t tiletodraw = combo_tile(c, 0, 0);
10461 flip = flip ^ c.flip;
10462
10463 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10464 }
10465
10466 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10467 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10468 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10469 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10470
10471 quad3d_f(refbmp, polytype, tex, &V1, &V2, &V3, &V4);
10472 if(mustDestroyBmp)
10473 destroy_bitmap(tex);
10474 }
10475 else
10476 {
10477
10478 if ( !bmptexture )
10479 {
10480 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Quad3D()");
10481 tex_is_bitmap = 0;
10482 return;
10483 }
10484 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10485 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10486 if ( !isPowerOfTwo(h) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10487 if ( !isPowerOfTwo(w) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Quad3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10488
10489 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10490 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10491 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10492 V3D_f V4 = { static_cast<float>(pos[9]+xoffset), static_cast<float>(pos[10]+yoffset), static_cast<float>(pos[11]), static_cast<float>(uv[6]), static_cast<float>(uv[7]), col[3] };
10493
10494 BITMAP *foo = create_bitmap_ex(8, 256, 176);
10495
10496 //quad3d_f(refbmp, polytype, foo, &V1, &V2, &V3, &V4);
10497 quad3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3, &V4);
10498 destroy_bitmap(foo);
10499
10500 }
10501
10502
10503
10504 }
10505
10506
10507
10508 void bmp_do_drawtriangle3dr(BITMAP *bmp, int32_t i, int32_t *sdci, int32_t xoffset, int32_t yoffset)
10509 {
10510 //sdci[1]=layer
10511 //sdci[2]=pos[9]
10512 //sdci[3]=uv[6]
10513 //sdci[4]=color[3]
10514 //sdci[5]=size[2]
10515 //sdci[6]=flip
10516 //sdci[7]=tile/combo
10517 //sdci[8]=polytype
10518 //sdci[9] bitmap as texture
10519 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10520 if ( sdci[DRAWCMD_BMP_TARGET] <= 0 )
10521 {
10522 Z_scripterrlog("bitmap->Triangle3D() wanted to write to an invalid bitmap id: %d. Aborting.\n", sdci[DRAWCMD_BMP_TARGET]);
10523 return;
10524 }
10525 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10526 if ( refbmp == NULL ) return;
10527
10528 std::vector<int32_t>* v_ptr = (std::vector<int32_t>*)script_drawing_commands[i].GetPtr();
10529
10530 if(!v_ptr)
10531 {
10532 al_trace("bitmap->Triangle3d: Vector pointer is null! Internal error. \n");
10533 return;
10534 }
10535
10536 std::vector<int32_t> &v = *v_ptr;
10537
10538 if(v.empty())
10539 return;
10540
10541 int32_t* pos = &v[0];
10542 int32_t* uv = &v[9];
10543 int32_t* col = &v[15];
10544 int32_t* size = &v[18];
10545
10546 int32_t w = size[0]; //magic numerical constants... yuck.
10547 int32_t h = size[1];
10548 int32_t flip = (sdci[6]/10000)&3;
10549 int32_t tile = sdci[7]/10000;
10550 int32_t polytype = sdci[8]/10000;
10551 int32_t quad_render_source = sdci[9];
10552 polytype = vbound(polytype, 0, 14);
10553
10554 if(((w-1) & w) != 0 || ((h-1) & h) != 0)
10555 {
10556 Z_message("bitmap->Triangle3d() : Args h, w, must be in powers of two! Power of 2 error with %i, %i.", w, h);
10557 return; //non power of two error
10558 }
10559
10560 int32_t tex_width = w*16;
10561 int32_t tex_height = h*16;
10562
10563 bool mustDestroyBmp = false;
10564 BITMAP *tex = script_drawing_commands.GetSmallTextureBitmap(w,h);
10565
10566 if(!tex)
10567 {
10568 mustDestroyBmp = true;
10569 tex = create_bitmap_ex(8, tex_width, tex_height);
10570 clear_bitmap(tex);
10571 }
10572
10573 bool tex_is_bitmap = ( sdci[9] != 0 );
10574 BITMAP *bmptexture=NULL;
10575 if ( tex_is_bitmap )
10576 {
10577 bmptexture = FFCore.GetScriptBitmap(quad_render_source);
10578 if ( !bmptexture )
10579 {
10580 Z_scripterrlog("Bitmap pointer used as a texture in %s is uninitialised.\n Defaulting to using a tile as a texture.\n", "bitmap->Triangle3()");
10581 tex_is_bitmap = 0;
10582 }
10583 }
10584
10585 if ( !tex_is_bitmap )
10586 {
10587 if(tile > 0) // TILE
10588 {
10589 TileHelper::OverTile(tex, tile, 0, 0, w, h, col[0], flip);
10590 }
10591 else // COMBO
10592 {
10593 const newcombo & c = combobuf[ vbound(abs(tile), 0, 0xffff) ];
10594 const int32_t tiletodraw = combo_tile(c, 0, 0);
10595 flip = flip ^ c.flip;
10596
10597 TileHelper::OldPutTile(tex, tiletodraw, 0, 0, w, h, col[0], flip);
10598 }
10599
10600 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10601 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10602 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10603
10604 triangle3d_f(refbmp, polytype, tex, &V1, &V2, &V3);
10605 }
10606 else
10607 {
10608 if ( !isPowerOfTwo(bmptexture->h) ) Z_scripterrlog("HEIGHT of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10609 if ( !isPowerOfTwo(bmptexture->w) ) Z_scripterrlog("WIDTH of Bitmap ( pointer %d ) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", quad_render_source);
10610 if ( !isPowerOfTwo(w) ) Z_scripterrlog("WIDTH ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", w);
10611 if ( !isPowerOfTwo(h) ) Z_scripterrlog("HEIGHT ARG (%d) provided as a render source for bitmap->Triangle3D is not a POWER OF TWO.\nTextels may render improperly!\n", h);
10612
10613 V3D_f V1 = { static_cast<float>(pos[0]+xoffset), static_cast<float>(pos[1] +yoffset), static_cast<float>(pos[2]), static_cast<float>(uv[0]), static_cast<float>(uv[1]), col[0] };
10614 V3D_f V2 = { static_cast<float>(pos[3]+xoffset), static_cast<float>(pos[4] +yoffset), static_cast<float>(pos[5]), static_cast<float>(uv[2]), static_cast<float>(uv[3]), col[1] };
10615 V3D_f V3 = { static_cast<float>(pos[6]+xoffset), static_cast<float>(pos[7] +yoffset), static_cast<float>(pos[8]), static_cast<float>(uv[4]), static_cast<float>(uv[5]), col[2] };
10616
10617 triangle3d_f(refbmp, polytype, bmptexture, &V1, &V2, &V3);
10618
10619
10620 }
10621 if(mustDestroyBmp)
10622 destroy_bitmap(tex);
10623
10624 }
10625
10626
10627 bool is_layer_transparent(const mapscr& m, int32_t layer)
10628 {
10629 layer = vbound(layer, 0, 5);
10630 return m.layeropacity[layer] == 128;
10631 }
10632
10633 4336942 mapscr *getmapscreen(int32_t map_index, int32_t screen_index, int32_t layer) //returns NULL for invalid or non-existent layer
10634 {
10635 mapscr *base_screen;
10636 4336942 int32_t index = map_index*MAPSCRS+screen_index;
10637
10638
2/4
✓ Branch 0 taken 4336942 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4336942 times.
4336942 if((uint32_t)layer > 6 || (uint32_t)index >= TheMaps.size())
10639 return NULL;
10640
10641
2/2
✓ Branch 0 taken 3552036 times.
✓ Branch 1 taken 784906 times.
4336942 if(layer != 0)
10642 {
10643 784906 layer = layer - 1;
10644
10645 784906 base_screen=&(TheMaps[index]);
10646
10647
2/2
✓ Branch 0 taken 748179 times.
✓ Branch 1 taken 36727 times.
784906 if(base_screen->layermap[layer]==0)
10648 36727 return NULL;
10649
10650 748179 index=(base_screen->layermap[layer]-1)*MAPSCRS+base_screen->layerscreen[layer];
10651
10652
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748179 times.
748179 if((uint32_t)index >= TheMaps.size()) // Might as well make sure
10653 return NULL;
10654 748179 }
10655
10656 4300215 return &(TheMaps[index]);
10657 4336942 }
10658
10659 191560 void draw_mapscr(BITMAP *b, const mapscr& m, int32_t x, int32_t y, bool transparent)
10660 {
10661
2/2
✓ Branch 0 taken 33714560 times.
✓ Branch 1 taken 191560 times.
33906120 for(int32_t i(0); i < 176; ++i)
10662 {
10663 33714560 const int32_t x2 = ((i&15)<<4) + x;
10664 33714560 const int32_t y2 = (i&0xF0) + y;
10665
10666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 33714560 times.
33714560 if(transparent)
10667 {
10668 overcomboblocktranslucent(b, x2, y2, m.data[i], m.cset[i], 1, 1, 128);
10669 }
10670 else
10671 {
10672 33714560 overcomboblock(b, x2, y2, m.data[i], m.cset[i], 1, 1);
10673 }
10674 33714560 }
10675 191560 }
10676
10677 void draw_map_solidity(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10678 {
10679 BITMAP* square = create_bitmap_ex(8,16,16);
10680
10681 for(int32_t i(0); i < 176; ++i)
10682 {
10683 const int32_t x2 = ((i&15)<<4) + x;
10684 const int32_t y2 = (i&0xF0) + y;
10685 //Blit the palette index of the solidity value.
10686 clear_to_color(square,(combobuf[m.data[i]].walk&15));
10687 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10688 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10689 }
10690 destroy_bitmap(square);
10691 }
10692
10693 void do_bmpdrawscreen_solidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10694 {
10695 //sdci[1]=layer
10696 //sdci[2]=map
10697 //sdci[3]=screen
10698 //sdci[4]=x
10699 //sdci[5]=y
10700 //sdci[6]=rotation
10701 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10702
10703 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10704 if ( refbmp == NULL ) return;
10705
10706 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10707
10708 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10709 int32_t scrn = sdci[3]/10000;
10710 int32_t x = sdci[4]/10000;
10711 int32_t y = sdci[5]/10000;
10712 int32_t x1 = x + xoffset;
10713 int32_t y1 = y + yoffset;
10714 int32_t rotation = sdci[6]/10000;
10715
10716 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10717
10718 if(index >= TheMaps.size())
10719 {
10720 al_trace("DrawScreen: invalid map or screen index. \n");
10721 return;
10722 }
10723
10724 const mapscr & m = TheMaps[index];
10725
10726
10727 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10728 if ( refbmp == NULL ) return;
10729
10730 if(rotation != 0)
10731 b = script_drawing_commands.AquireSubBitmap(256, 176);
10732
10733 //draw layer 0
10734 draw_map_solidity(b, m, x1, y1);
10735 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10736 {
10737 for(int32_t i(0); i < 6; ++i)
10738 {
10739 if(m.layermap[i] == 0) continue;
10740
10741 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10742
10743 if(layer_screen_index >= TheMaps.size())
10744 continue;
10745
10746 //draw valid layers
10747 draw_map_solidity(b, TheMaps[ layer_screen_index ], x1, y1);
10748 }
10749 }
10750
10751 if(rotation != 0) // rotate
10752 {
10753 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10754 script_drawing_commands.ReleaseSubBitmap(b);
10755 }
10756 }
10757
10758 void draw_map_solid(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10759 {
10760 BITMAP* square = create_bitmap_ex(8,16,16);
10761 BITMAP* subsquare = create_bitmap_ex(8,16,16);
10762 clear_to_color(subsquare,1);
10763
10764 for(int32_t i(0); i < 176; ++i)
10765 {
10766 const int32_t x2 = ((i&15)<<4) + x;
10767 const int32_t y2 = (i&0xF0) + y;
10768 //Blit the palette index of the solidity value.
10769 clear_bitmap(square);
10770 int32_t sol = (combobuf[m.data[i]].walk);
10771 if ( sol & 1 )
10772 {
10773 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
10774 }
10775 if ( sol & 2 )
10776 {
10777 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
10778 }
10779 if ( sol & 4 )
10780 {
10781 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
10782 }
10783 if ( sol &8 ) {
10784 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
10785 }
10786
10787 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10788 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10789 }
10790 destroy_bitmap(square);
10791 destroy_bitmap(subsquare);
10792 }
10793
10794 void do_bmpdrawscreen_solidr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10795 {
10796 //sdci[1]=layer
10797 //sdci[2]=map
10798 //sdci[3]=screen
10799 //sdci[4]=x
10800 //sdci[5]=y
10801 //sdci[6]=rotation
10802 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10803
10804 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10805 if ( refbmp == NULL ) return;
10806
10807 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10808
10809 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10810 int32_t scrn = sdci[3]/10000;
10811 int32_t x = sdci[4]/10000;
10812 int32_t y = sdci[5]/10000;
10813 int32_t x1 = x + xoffset;
10814 int32_t y1 = y + yoffset;
10815 int32_t rotation = sdci[6]/10000;
10816
10817 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10818
10819 if(index >= TheMaps.size())
10820 {
10821 al_trace("DrawScreen: invalid map or screen index. \n");
10822 return;
10823 }
10824
10825 const mapscr & m = TheMaps[index];
10826
10827
10828 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10829 if ( refbmp == NULL ) return;
10830
10831 if(rotation != 0)
10832 b = script_drawing_commands.AquireSubBitmap(256, 176);
10833
10834 //draw layer 0
10835 draw_map_solid(b, m, x1, y1);
10836
10837 for(int32_t i(0); i < 6; ++i) //This one doesn't need the QR; it works just fine.
10838 {
10839 if(m.layermap[i] == 0) continue;
10840
10841 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10842
10843 if(layer_screen_index >= TheMaps.size())
10844 continue;
10845
10846 //draw valid layers
10847 draw_map_solid(b, TheMaps[ layer_screen_index ], x1, y1);
10848 }
10849
10850 if(rotation != 0) // rotate
10851 {
10852 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10853 script_drawing_commands.ReleaseSubBitmap(b);
10854 }
10855 }
10856
10857 1024 void draw_map_cflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10858 {
10859 1024 BITMAP* square = create_bitmap_ex(8,16,16);
10860
10861
2/2
✓ Branch 0 taken 180224 times.
✓ Branch 1 taken 1024 times.
181248 for(int32_t i(0); i < 176; ++i)
10862 {
10863 180224 const int32_t x2 = ((i&15)<<4) + x;
10864 180224 const int32_t y2 = (i&0xF0) + y;
10865 //Blit the palette index of the solidity value.
10866 180224 clear_to_color(square,m.sflag[i]);
10867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 180224 times.
180224 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10868 180224 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10869 180224 }
10870 1024 destroy_bitmap(square);
10871 1024 }
10872
10873 1024 void do_bmpdrawscreen_cflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10874 {
10875 //sdci[1]=layer
10876 //sdci[2]=map
10877 //sdci[3]=screen
10878 //sdci[4]=x
10879 //sdci[5]=y
10880 //sdci[6]=rotation
10881 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10882
10883 1024 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10884
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10885
10886
2/4
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1024 times.
✗ Branch 3 not taken.
1024 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10887
10888 1024 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10889 1024 int32_t scrn = sdci[3]/10000;
10890 1024 int32_t x = sdci[4]/10000;
10891 1024 int32_t y = sdci[5]/10000;
10892 1024 int32_t x1 = x + xoffset;
10893 1024 int32_t y1 = y + yoffset;
10894 1024 int32_t rotation = sdci[6]/10000;
10895
10896 1024 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10897
10898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1024 times.
1024 if(index >= TheMaps.size())
10899 {
10900 al_trace("DrawScreen: invalid map or screen index. \n");
10901 return;
10902 }
10903
10904 1024 const mapscr & m = TheMaps[index];
10905
10906
10907 1024 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10908
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if ( refbmp == NULL ) return;
10909
10910
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0)
10911 b = script_drawing_commands.AquireSubBitmap(256, 176);
10912
10913 //draw layer 0
10914 1024 draw_map_cflag(b, m, x1, y1);
10915
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10916 {
10917 for(int32_t i(0); i < 6; ++i)
10918 {
10919 if(m.layermap[i] == 0) continue;
10920
10921 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
10922
10923 if(layer_screen_index >= TheMaps.size())
10924 continue;
10925
10926 //draw valid layers
10927 draw_map_cflag(b, TheMaps[ layer_screen_index ], x1, y1);
10928 }
10929 }
10930
10931
1/2
✓ Branch 0 taken 1024 times.
✗ Branch 1 not taken.
1024 if(rotation != 0) // rotate
10932 {
10933 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
10934 script_drawing_commands.ReleaseSubBitmap(b);
10935 }
10936 1024 }
10937
10938
10939 void draw_map_combotype(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
10940 {
10941 BITMAP* square = create_bitmap_ex(8,16,16);
10942
10943 for(int32_t i(0); i < 176; ++i)
10944 {
10945 const int32_t x2 = ((i&15)<<4) + x;
10946 const int32_t y2 = (i&0xF0) + y;
10947 //Blit the palette index of the solidity value.
10948 clear_to_color(square,(combobuf[m.data[i]].type));
10949 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
10950 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
10951 }
10952 destroy_bitmap(square);
10953 }
10954
10955 void do_bmpdrawscreen_ctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
10956 {
10957 //sdci[1]=layer
10958 //sdci[2]=map
10959 //sdci[3]=screen
10960 //sdci[4]=x
10961 //sdci[5]=y
10962 //sdci[6]=rotation
10963 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
10964
10965 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10966 if ( refbmp == NULL ) return;
10967
10968 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
10969
10970 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
10971 int32_t scrn = sdci[3]/10000;
10972 int32_t x = sdci[4]/10000;
10973 int32_t y = sdci[5]/10000;
10974 int32_t x1 = x + xoffset;
10975 int32_t y1 = y + yoffset;
10976 int32_t rotation = sdci[6]/10000;
10977
10978 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
10979
10980 if(index >= TheMaps.size())
10981 {
10982 al_trace("DrawScreen: invalid map or screen index. \n");
10983 return;
10984 }
10985
10986 const mapscr & m = TheMaps[index];
10987
10988
10989 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
10990 if ( refbmp == NULL ) return;
10991
10992 if(rotation != 0)
10993 b = script_drawing_commands.AquireSubBitmap(256, 176);
10994
10995 //draw layer 0
10996 draw_map_combotype(b, m, x1, y1);
10997
10998 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
10999 {
11000 for(int32_t i(0); i < 6; ++i)
11001 {
11002 if(m.layermap[i] == 0) continue;
11003
11004 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11005
11006 if(layer_screen_index >= TheMaps.size())
11007 continue;
11008
11009 //draw valid layers
11010 draw_map_combotype(b, TheMaps[ layer_screen_index ], x1, y1);
11011 }
11012 }
11013
11014 if(rotation != 0) // rotate
11015 {
11016 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11017 script_drawing_commands.ReleaseSubBitmap(b);
11018 }
11019 }
11020
11021
11022 void draw_map_comboiflag(BITMAP *b, const mapscr& m, int32_t x, int32_t y)
11023 {
11024 BITMAP* square = create_bitmap_ex(8,16,16);
11025
11026 for(int32_t i(0); i < 176; ++i)
11027 {
11028 const int32_t x2 = ((i&15)<<4) + x;
11029 const int32_t y2 = (i&0xF0) + y;
11030 //Blit the palette index of the solidity value.
11031 clear_to_color(square,(combobuf[m.data[i]].flag));
11032 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS)) blit(square, b, 0, 0, x2, y2, square->w, square->h);
11033 else masked_blit(square, b, 0, 0, x2, y2, square->w, square->h);
11034 }
11035 destroy_bitmap(square);
11036 }
11037
11038 void do_bmpdrawscreen_ciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11039 {
11040 //sdci[1]=layer
11041 //sdci[2]=map
11042 //sdci[3]=screen
11043 //sdci[4]=x
11044 //sdci[5]=y
11045 //sdci[6]=rotation
11046 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11047
11048 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11049 if ( refbmp == NULL ) return;
11050
11051 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11052
11053 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11054 int32_t scrn = sdci[3]/10000;
11055 int32_t x = sdci[4]/10000;
11056 int32_t y = sdci[5]/10000;
11057 int32_t x1 = x + xoffset;
11058 int32_t y1 = y + yoffset;
11059 int32_t rotation = sdci[6]/10000;
11060
11061 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11062
11063 if(index >= TheMaps.size())
11064 {
11065 al_trace("DrawScreen: invalid map or screen index. \n");
11066 return;
11067 }
11068
11069 const mapscr & m = TheMaps[index];
11070
11071
11072 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11073 if ( refbmp == NULL ) return;
11074
11075 if(rotation != 0)
11076 b = script_drawing_commands.AquireSubBitmap(256, 176);
11077
11078 //draw layer 0
11079 draw_map_comboiflag(b, m, x1, y1);
11080
11081 if (get_qr(qr_BROKEN_DRAWSCREEN_FUNCTIONS))
11082 {
11083 for(int32_t i(0); i < 6; ++i)
11084 {
11085 if(m.layermap[i] == 0) continue;
11086
11087 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11088
11089 if(layer_screen_index >= TheMaps.size())
11090 continue;
11091
11092 //draw valid layers
11093 draw_map_comboiflag(b, TheMaps[ layer_screen_index ], x1, y1);
11094 }
11095 }
11096
11097 if(rotation != 0) // rotate
11098 {
11099 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11100 script_drawing_commands.ReleaseSubBitmap(b);
11101 }
11102 }
11103
11104 4335769 void do_drawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11105 {
11106 //sdci[1]=layer
11107 //sdci[2]=map
11108 //sdci[3]=screen
11109 //sdci[4]=layer
11110 //sdci[5]=x
11111 //sdci[6]=y
11112 //sdci[7]=rotation
11113 //sdci[8]=opacity
11114
11115 4335769 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11116 4335769 int32_t scrn = sdci[3]/10000;
11117 4335769 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11118 4335769 int32_t x = sdci[5]/10000;
11119 4335769 int32_t y = sdci[6]/10000;
11120 4335769 int32_t x1 = x + xoffset;
11121 4335769 int32_t y1 = y + yoffset;
11122 4335769 int32_t rotation = sdci[7]/10000;
11123 4335769 int32_t opacity = sdci[8]/10000;
11124
11125 4335769 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11126 4335769 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11127
11128
2/2
✓ Branch 0 taken 4299048 times.
✓ Branch 1 taken 36721 times.
4335769 if(!m) //no need to log it.
11129 36721 return;
11130
11131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(index >= TheMaps.size())
11132 {
11133 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11134 return;
11135 }
11136
11137 4299048 const mapscr & l = *m;
11138
11139 4299048 BITMAP* b = bmp;
11140
11141
1/2
✓ Branch 0 taken 4299048 times.
✗ Branch 1 not taken.
4299048 if(rotation != 0)
11142 b = script_drawing_commands.AquireSubBitmap(256, 176);
11143
11144
11145 4299048 const int32_t maxX = isOffScreen ? 512 : 256;
11146
2/2
✓ Branch 0 taken 4280939 times.
✓ Branch 1 taken 18109 times.
4299048 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11147 4299048 bool transparent = opacity <= 128;
11148
11149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4299048 times.
4299048 if(rotation != 0) // rotate
11150 {
11151 draw_mapscr(b, l, x1, y1, transparent);
11152
11153 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11154 script_drawing_commands.ReleaseSubBitmap(b);
11155 }
11156 else
11157 {
11158
2/2
✓ Branch 0 taken 756632448 times.
✓ Branch 1 taken 4299048 times.
760931496 for(int32_t i(0); i < 176; ++i)
11159 {
11160 756632448 const int32_t x2 = ((i&15)<<4) + x1;
11161 756632448 const int32_t y2 = (i&0xF0) + y1;
11162
11163
7/8
✓ Branch 0 taken 666127814 times.
✓ Branch 1 taken 90504634 times.
✓ Branch 2 taken 666127814 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 611722422 times.
✓ Branch 5 taken 54405392 times.
✓ Branch 6 taken 9155742 times.
✓ Branch 7 taken 602566680 times.
756632448 if(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY) //in clipping rect
11164 {
11165 602566680 const newcombo & c = combobuf[ l.data[i] ];
11166 602566680 const int32_t tile = combo_tile(c, x2, y2);
11167
11168
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 602566680 times.
602566680 if(opacity < 128)
11169 {
11170 overcomboblocktranslucent(b, x2, y2, l.data[i], l.cset[i], 1, 1, 128);
11171
11172
11173 //overtiletranslucent16(b, tile, x2, y2, l.cset[i], c.flip, opacity);
11174 }
11175 else
11176 {
11177 602566680 overcomboblock(b, x2, y2, l.data[i], l.cset[i], 1, 1);
11178 //overtile16(b, tile, x2, y2, l.cset[i], c.flip);
11179 }
11180 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11181 602566680 }
11182 756632448 }
11183 }
11184
11185 //putscr
11186 4335769 }
11187
11188
11189
11190 50406 void do_drawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11191 {
11192 //sdci[1]=layer
11193 //sdci[2]=map
11194 //sdci[3]=screen
11195 //sdci[4]=x
11196 //sdci[5]=y
11197 //sdci[6]=rotation
11198
11199 50406 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11200 50406 int32_t scrn = sdci[3]/10000;
11201 50406 int32_t x = sdci[4]/10000;
11202 50406 int32_t y = sdci[5]/10000;
11203 50406 int32_t x1 = x + xoffset;
11204 50406 int32_t y1 = y + yoffset;
11205 50406 int32_t rotation = sdci[6]/10000;
11206
11207 50406 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11208
11209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(index >= TheMaps.size())
11210 {
11211 al_trace("DrawScreen: invalid map or screen index. \n");
11212 return;
11213 }
11214
11215 50406 const mapscr & m = TheMaps[index];
11216
11217
11218 50406 BITMAP* b = bmp;
11219
11220
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0)
11221 b = script_drawing_commands.AquireSubBitmap(256, 176);
11222
11223 //draw layer 0
11224 50406 draw_mapscr(b, m, x1, y1, false);
11225
11226
2/2
✓ Branch 0 taken 50406 times.
✓ Branch 1 taken 302436 times.
352842 for(int32_t i(0); i < 6; ++i)
11227 {
11228
2/2
✓ Branch 0 taken 137944 times.
✓ Branch 1 taken 164492 times.
302436 if(m.layermap[i] == 0) continue;
11229
11230 137944 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11231
11232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 137944 times.
137944 if(layer_screen_index >= TheMaps.size())
11233 continue;
11234
11235 137944 bool trans = m.layeropacity[i] == 128;
11236
11237 //draw valid layers
11238 137944 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11239 137944 }
11240
11241
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50406 times.
50406 if(rotation != 0) // rotate
11242 {
11243 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11244 script_drawing_commands.ReleaseSubBitmap(b);
11245 }
11246 50406 }
11247
11248
11249 1173 void do_bmpdrawlayerr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11250 {
11251 //sdci[1]=layer
11252 //sdci[2]=map
11253 //sdci[3]=screen
11254 //sdci[4]=layer
11255 //sdci[5]=x
11256 //sdci[6]=y
11257 //sdci[7]=rotation
11258 //[8] noclip
11259 //sdci[9]=opacity
11260 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11261
11262 1173 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11263
1/2
✓ Branch 0 taken 1173 times.
✗ Branch 1 not taken.
1173 if ( refbmp == NULL ) return;
11264
11265 1173 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11266 1173 int32_t scrn = sdci[3]/10000;
11267 1173 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11268 1173 int32_t x = sdci[5]/10000;
11269 1173 int32_t y = sdci[6]/10000;
11270 1173 int32_t rotation = sdci[7]/10000;
11271
11272 1173 byte noclip = 0;//(sdci[8]!=0);
11273 1173 int32_t opacity = sdci[8]/10000;
11274 1173 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11275 1173 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11276
11277
2/2
✓ Branch 0 taken 1167 times.
✓ Branch 1 taken 6 times.
1173 if(!m) //no need to log it.
11278 6 return;
11279
11280
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(index >= TheMaps.size())
11281 {
11282 Z_scripterrlog("DrawLayer: invalid map index \"%i\". Map count is %d.\n", index, TheMaps.size());
11283 return;
11284 }
11285
11286 1167 const mapscr & l = *m;
11287
11288 1167 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11289
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if ( refbmp == NULL ) return;
11290
2/4
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1167 times.
✗ Branch 3 not taken.
1167 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11291
1/2
✓ Branch 0 taken 1167 times.
✗ Branch 1 not taken.
1167 if(rotation != 0)
11292 b = script_drawing_commands.AquireSubBitmap(256, 176);
11293
11294
11295 1167 const int32_t maxX = isOffScreen ? 512 : 256;
11296
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11297 1167 bool transparent = opacity <= 128;
11298
11299
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1167 times.
1167 if(rotation != 0) // rotate
11300 {
11301 draw_mapscr(b, l, x, y, transparent);
11302
11303 rotate_sprite(refbmp, b, x, y, degrees_to_fixed(rotation));
11304 script_drawing_commands.ReleaseSubBitmap(b);
11305 }
11306 else
11307 {
11308
2/2
✓ Branch 0 taken 205392 times.
✓ Branch 1 taken 1167 times.
206559 for(int32_t i(0); i < 176; ++i)
11309 {
11310 205392 const int32_t x2 = ((i&15)<<4) + x;
11311 205392 const int32_t y2 = (i&0xF0) + y;
11312
11313 //if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11314 {
11315 205392 const newcombo & c = combobuf[ l.data[i] ];
11316 205392 const int32_t tile = combo_tile(c, x2, y2);
11317
11318
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 205392 times.
205392 if(opacity < 128)
11319 overtiletranslucent16(refbmp, tile, x2, y2, l.cset[i], c.flip, opacity);
11320 else
11321 205392 overtile16(refbmp, tile, x2, y2, l.cset[i], c.flip);
11322
11323 //putcombo( b, xx, yy, l.data[i], l.cset[i] );
11324 }
11325 205392 }
11326 }
11327
11328 //putscr
11329 1173 }
11330
11331
11332
11333 1092 void do_bmpdrawscreenr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11334 {
11335 //sdci[1]=layer
11336 //sdci[2]=map
11337 //sdci[3]=screen
11338 //sdci[4]=x
11339 //sdci[5]=y
11340 //sdci[6]=rotation
11341 //sdci[DRAWCMD_BMP_TARGET] Bitmap Pointer
11342
11343 1092 BITMAP *refbmp = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11344
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if ( refbmp == NULL ) return;
11345
11346
2/4
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1092 times.
1092 if ( (sdci[DRAWCMD_BMP_TARGET]-10) != -2 && (sdci[DRAWCMD_BMP_TARGET]-10) != -1 ) yoffset = 0; //Don't crop.
11347
11348 1092 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11349 1092 int32_t scrn = sdci[3]/10000;
11350 1092 int32_t x = sdci[4]/10000;
11351 1092 int32_t y = sdci[5]/10000;
11352 1092 int32_t x1 = x + xoffset;
11353 1092 int32_t y1 = y + yoffset;
11354 1092 int32_t rotation = sdci[6]/10000;
11355
11356 1092 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11357
11358
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if(index >= TheMaps.size())
11359 {
11360 al_trace("DrawScreen: invalid map or screen index. \n");
11361 return;
11362 }
11363
11364 1092 const mapscr & m = TheMaps[index];
11365
11366
11367 1092 BITMAP* b = FFCore.GetScriptBitmap(sdci[DRAWCMD_BMP_TARGET]);
11368
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1092 times.
1092 if ( refbmp == NULL ) return;
11369
11370
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0)
11371 b = script_drawing_commands.AquireSubBitmap(256, 176);
11372
11373 //draw layer 0
11374 1092 draw_mapscr(b, m, x1, y1, false);
11375
11376
2/2
✓ Branch 0 taken 1092 times.
✓ Branch 1 taken 6552 times.
7644 for(int32_t i(0); i < 6; ++i)
11377 {
11378
2/2
✓ Branch 0 taken 2118 times.
✓ Branch 1 taken 4434 times.
6552 if(m.layermap[i] == 0) continue;
11379
11380 2118 uint32_t layer_screen_index = (m.layermap[i]-1) * MAPSCRS + m.layerscreen[i];
11381
11382
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2118 times.
2118 if(layer_screen_index >= TheMaps.size())
11383 continue;
11384
11385 2118 bool trans = m.layeropacity[i] == 128;
11386
11387 //draw valid layers
11388 2118 draw_mapscr(b, TheMaps[ layer_screen_index ], x1, y1, trans);
11389 2118 }
11390
11391
1/2
✓ Branch 0 taken 1092 times.
✗ Branch 1 not taken.
1092 if(rotation != 0) // rotate
11392 {
11393 rotate_sprite(refbmp, b, x1, y1, degrees_to_fixed(rotation));
11394 script_drawing_commands.ReleaseSubBitmap(b);
11395 }
11396 1092 }
11397
11398 void do_bmpdrawlayersolidmaskr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11399 {
11400 //sdci[1]=layer
11401 //sdci[2]=map
11402 //sdci[3]=screen
11403 //sdci[4]=layer
11404 //sdci[5]=x
11405 //sdci[6]=y
11406 //sdci[7]=rotation
11407 //sdci[8]=bool noclip
11408 //sdci[9] == opacity
11409
11410 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11411 int32_t scrn = sdci[3]/10000;
11412 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11413 int32_t x = sdci[5]/10000;
11414 int32_t y = sdci[6]/10000;
11415 int32_t x1 = x + xoffset;
11416 int32_t y1 = y + yoffset;
11417 int32_t rotation = sdci[7]/10000;
11418 byte noclip = (sdci[8]!=0);
11419 int32_t opacity = sdci[9]/10000;
11420
11421 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11422 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11423
11424 if(!m) //no need to log it.
11425 return;
11426
11427 if(index >= TheMaps.size())
11428 {
11429 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11430 return;
11431 }
11432
11433 const mapscr & l = *m;
11434
11435 BITMAP* b = bmp;
11436
11437 if(rotation != 0)
11438 b = script_drawing_commands.AquireSubBitmap(256, 176);
11439
11440
11441 const int32_t maxX = isOffScreen ? 512 : 256;
11442 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11443 bool transparent = opacity <= 128;
11444
11445 if(rotation != 0) // rotate
11446 {
11447 draw_map_solid(b, l, x1, y1);
11448
11449 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11450 script_drawing_commands.ReleaseSubBitmap(b);
11451 }
11452 else
11453 {
11454 BITMAP* square = create_bitmap_ex(8,16,16);
11455 BITMAP* subsquare = create_bitmap_ex(8,16,16);
11456 clear_to_color(subsquare,1);
11457 for(int32_t i(0); i < 176; ++i)
11458 {
11459 const int32_t x2 = ((i&15)<<4) + x1;
11460 const int32_t y2 = (i&0xF0) + y1;
11461
11462 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11463 {
11464 int32_t sol = (combobuf[l.data[i]].walk);
11465
11466 if ( sol & 1 )
11467 {
11468 blit(subsquare, square, 0, 0, 0, 0, 8, 8);
11469 }
11470 if ( sol & 2 )
11471 {
11472 blit(subsquare, square, 0, 0, 0, 8, 8, 8);
11473 }
11474 if ( sol & 4 )
11475 {
11476 blit(subsquare, square, 0, 0, 8, 0, 8, 8);
11477 }
11478 if ( sol &8 ) {
11479 blit(subsquare, square, 0, 0, 8, 8, 8, 8);
11480 }
11481
11482 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11483 }
11484 }
11485 destroy_bitmap(square);
11486 destroy_bitmap(subsquare);
11487 }
11488
11489 //putscr
11490 }
11491
11492 void do_bmpdrawlayersolidityr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11493 {
11494 //sdci[1]=layer
11495 //sdci[2]=map
11496 //sdci[3]=screen
11497 //sdci[4]=layer
11498 //sdci[5]=x
11499 //sdci[6]=y
11500 //sdci[7]=rotation
11501 //[8] noclip
11502 //sdci[9]=opacity
11503
11504
11505 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11506 int32_t scrn = sdci[3]/10000;
11507 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11508 int32_t x = sdci[5]/10000;
11509 int32_t y = sdci[6]/10000;
11510 int32_t x1 = x + xoffset;
11511 int32_t y1 = y + yoffset;
11512 int32_t rotation = sdci[7]/10000;
11513 byte noclip = (sdci[8]!=0);
11514 int32_t opacity = sdci[9]/10000;
11515
11516 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11517 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11518
11519 if(!m) //no need to log it.
11520 return;
11521
11522 if(index >= TheMaps.size())
11523 {
11524 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11525 return;
11526 }
11527
11528 const mapscr & l = *m;
11529
11530 BITMAP* b = bmp;
11531
11532 if(rotation != 0)
11533 b = script_drawing_commands.AquireSubBitmap(256, 176);
11534
11535
11536 const int32_t maxX = isOffScreen ? 512 : 256;
11537 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11538 bool transparent = opacity <= 128;
11539
11540 if(rotation != 0) // rotate
11541 {
11542 draw_map_solidity(b, l, x1, y1);
11543
11544 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11545 script_drawing_commands.ReleaseSubBitmap(b);
11546 }
11547 else
11548 {
11549 BITMAP* square = create_bitmap_ex(8,16,16);
11550 for(int32_t i(0); i < 176; ++i)
11551 {
11552 const int32_t x2 = ((i&15)<<4) + x1;
11553 const int32_t y2 = (i&0xF0) + y1;
11554
11555 if(noclip && (x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11556 {
11557 clear_to_color(square,(combobuf[l.data[i]].walk&15));
11558 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11559 }
11560 }
11561 destroy_bitmap(square);
11562 }
11563
11564 //putscr
11565 }
11566
11567 void do_bmpdrawlayercflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11568 {
11569 //sdci[1]=layer
11570 //sdci[2]=map
11571 //sdci[3]=screen
11572 //sdci[4]=layer
11573 //sdci[5]=x
11574 //sdci[6]=y
11575 //sdci[7]=rotation
11576 //[8] noclip
11577 //sdci[9]=opacity
11578
11579
11580 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11581 int32_t scrn = sdci[3]/10000;
11582 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11583 int32_t x = sdci[5]/10000;
11584 int32_t y = sdci[6]/10000;
11585 int32_t x1 = x + xoffset;
11586 int32_t y1 = y + yoffset;
11587 int32_t rotation = sdci[7]/10000;
11588
11589 byte noclip = (sdci[8]!=0);
11590 int32_t opacity = sdci[9]/10000;
11591
11592 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11593 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11594
11595 if(!m) //no need to log it.
11596 return;
11597
11598 if(index >= TheMaps.size())
11599 {
11600 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11601 return;
11602 }
11603
11604 const mapscr & l = *m;
11605
11606 BITMAP* b = bmp;
11607
11608 if(rotation != 0)
11609 b = script_drawing_commands.AquireSubBitmap(256, 176);
11610
11611
11612 const int32_t maxX = isOffScreen ? 512 : 256;
11613 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11614 bool transparent = opacity <= 128;
11615
11616 if(rotation != 0) // rotate
11617 {
11618 draw_map_cflag(b, l, x1, y1);
11619
11620 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11621 script_drawing_commands.ReleaseSubBitmap(b);
11622 }
11623 else
11624 {
11625 BITMAP* square = create_bitmap_ex(8,16,16);
11626 for(int32_t i(0); i < 176; ++i)
11627 {
11628 const int32_t x2 = ((i&15)<<4) + x1;
11629 const int32_t y2 = (i&0xF0) + y1;
11630
11631 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11632 {
11633 clear_to_color(square,l.sflag[i]);
11634 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11635 }
11636 }
11637 destroy_bitmap(square);
11638 }
11639
11640 //putscr
11641 }
11642
11643 void do_bmpdrawlayerctyper(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11644 {
11645 //sdci[1]=layer
11646 //sdci[2]=map
11647 //sdci[3]=screen
11648 //sdci[4]=layer
11649 //sdci[5]=x
11650 //sdci[6]=y
11651 //sdci[7]=rotation
11652 //[8] noclip
11653 //sdci[9]=opacity
11654
11655 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11656 int32_t scrn = sdci[3]/10000;
11657 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11658 int32_t x = sdci[5]/10000;
11659 int32_t y = sdci[6]/10000;
11660 int32_t x1 = x + xoffset;
11661 int32_t y1 = y + yoffset;
11662 int32_t rotation = sdci[7]/10000;
11663
11664 byte noclip = (sdci[8]!=0);
11665 int32_t opacity = sdci[9]/10000;
11666 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11667 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11668
11669 if(!m) //no need to log it.
11670 return;
11671
11672 if(index >= TheMaps.size())
11673 {
11674 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11675 return;
11676 }
11677
11678 const mapscr & l = *m;
11679
11680 BITMAP* b = bmp;
11681
11682 if(rotation != 0)
11683 b = script_drawing_commands.AquireSubBitmap(256, 176);
11684
11685
11686 const int32_t maxX = isOffScreen ? 512 : 256;
11687 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11688 bool transparent = opacity <= 128;
11689
11690 if(rotation != 0) // rotate
11691 {
11692 draw_map_combotype(b, l, x1, y1);
11693
11694 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11695 script_drawing_commands.ReleaseSubBitmap(b);
11696 }
11697 else
11698 {
11699 BITMAP* square = create_bitmap_ex(8,16,16);
11700 for(int32_t i(0); i < 176; ++i)
11701 {
11702 const int32_t x2 = ((i&15)<<4) + x1;
11703 const int32_t y2 = (i&0xF0) + y1;
11704
11705 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11706 {
11707 clear_to_color(square,(combobuf[l.data[i]].type));
11708 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11709 }
11710 }
11711 destroy_bitmap(square);
11712 }
11713
11714 //putscr
11715 }
11716
11717 void do_bmpdrawlayerciflagr(BITMAP *bmp, int32_t *sdci, int32_t xoffset, int32_t yoffset, bool isOffScreen)
11718 {
11719 //sdci[1]=layer
11720 //sdci[2]=map
11721 //sdci[3]=screen
11722 //sdci[4]=layer
11723 //sdci[5]=x
11724 //sdci[6]=y
11725 //sdci[7]=rotation
11726 //[8] noclip
11727 //sdci[9]=opacity
11728
11729 int32_t map = (sdci[2]/10000)-1; //zscript map indices start at 1.
11730 int32_t scrn = sdci[3]/10000;
11731 int32_t sourceLayer = vbound(sdci[4]/10000, 0, 6);
11732 int32_t x = sdci[5]/10000;
11733 int32_t y = sdci[6]/10000;
11734 int32_t x1 = x + xoffset;
11735 int32_t y1 = y + yoffset;
11736 int32_t rotation = sdci[7]/10000;
11737 byte noclip = (sdci[8]!=0);
11738 int32_t opacity = sdci[9]/10000;
11739
11740 const uint32_t index = (uint32_t)(map * MAPSCRS + scrn);
11741 const mapscr* m = getmapscreen(map, scrn, sourceLayer);
11742
11743 if(!m) //no need to log it.
11744 return;
11745
11746 if(index >= TheMaps.size())
11747 {
11748 al_trace("DrawLayer: invalid map index \"%i\". Map count is %lu.\n", index, TheMaps.size());
11749 return;
11750 }
11751
11752 const mapscr & l = *m;
11753
11754 BITMAP* b = bmp;
11755
11756 if(rotation != 0)
11757 b = script_drawing_commands.AquireSubBitmap(256, 176);
11758
11759
11760 const int32_t maxX = isOffScreen ? 512 : 256;
11761 const int32_t maxY = isOffScreen ? 512 : 176 + yoffset;
11762 bool transparent = opacity <= 128;
11763
11764 if(rotation != 0) // rotate
11765 {
11766 draw_map_comboiflag(b, l, x1, y1);
11767
11768 rotate_sprite(bmp, b, x1, y1, degrees_to_fixed(rotation));
11769 script_drawing_commands.ReleaseSubBitmap(b);
11770 }
11771 else
11772 {
11773 BITMAP* square = create_bitmap_ex(8,16,16);
11774 for(int32_t i(0); i < 176; ++i)
11775 {
11776 const int32_t x2 = ((i&15)<<4) + x1;
11777 const int32_t y2 = (i&0xF0) + y1;
11778
11779 if(noclip&&(x2 > -16 && x2 < maxX && y2 > -16 && y2 < maxY)) //in clipping rect
11780 {
11781 clear_to_color(square,(combobuf[l.data[i]].flag));
11782 blit(square, b, 0, 0, x2, y2, square->w, square->h);
11783 }
11784 }
11785 destroy_bitmap(square);
11786 }
11787
11788 //putscr
11789 }
11790
11791
11792
11793 /////////////////////////////////////////////////////////
11794 // do primitives
11795 ////////////////////////////////////////////////////////
11796
11797 398566646 void do_primitives(BITMAP *targetBitmap, int32_t type, mapscr* theScreen, int32_t xoff, int32_t yoff)
11798 {
11799 398566646 color_map = &trans_table2;
11800
11801 //was this next variable ever used? -- DN
11802 //bool drawsubscr=false;
11803
11804
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 398566646 times.
398566646 if(type > 7)
11805 return;
11806
3/4
✓ Branch 0 taken 126606044 times.
✓ Branch 1 taken 271960602 times.
✓ Branch 2 taken 126606044 times.
✗ Branch 3 not taken.
398566646 if(type >= 0 && theScreen->hidescriptlayers & (1<<type))
11807 return; //Script draws hidden for this layer
11808
2/2
✓ Branch 0 taken 3207885 times.
✓ Branch 1 taken 395358761 times.
398566646 if(!script_drawing_commands.is_dirty(type))
11809 395358761 return; //No draws to this layer
11810 //--script_drawing_commands[][] reference--
11811 //[][0]: type
11812 //[][1-16]: defined by type
11813 //...
11814 //[][DRAWCMD_BMP_TARGET]: bitmap pointer
11815 //[][DRAWCMD_CURRENT_TARGET]: current render target at time command is queued? unused?
11816
11817 3207885 const int32_t type_mul_10000 = type * 10000;
11818 3207885 const int32_t numDrawCommandsToProcess = script_drawing_commands.Count();
11819 3207885 FFCore.numscriptdraws = numDrawCommandsToProcess;
11820
11821
2/2
✓ Branch 0 taken 297633815 times.
✓ Branch 1 taken 3207885 times.
300841700 for(int32_t i(0); i < numDrawCommandsToProcess; ++i)
11822 {
11823 297633815 int32_t *sdci = &script_drawing_commands[i][0];
11824
11825
2/2
✓ Branch 0 taken 198736391 times.
✓ Branch 1 taken 98897424 times.
297633815 if(sdci[1] != type_mul_10000)
11826 198736391 continue;
11827
11828 // get the correct render target, if set.
11829 98897424 BITMAP *bmp = zscriptDrawingRenderTarget->GetTargetBitmap(sdci[DRAWCMD_CURRENT_TARGET]);
11830 int32_t xoffset;
11831 int32_t yoffset;
11832 // TODO: the way this is used is unusual. bitmaps can be of any size, yet this clips based on a fixed size.
11833 // Should just remove all clipping at this layer, the underlying draw functions clip anyway.
11834 bool isTargetOffScreenBmp;
11835
11836
2/2
✓ Branch 0 taken 6429021 times.
✓ Branch 1 taken 92468403 times.
98897424 if(!bmp)
11837 {
11838 // draw to screen with subscreen offset
11839 92468403 xoffset = xoff;
11840 92468403 yoffset = yoff;
11841 92468403 bmp = targetBitmap;
11842 92468403 isTargetOffScreenBmp = false;
11843 92468403 }
11844 else
11845 {
11846 //not drawing to screen, so no subscreen offset
11847 6429021 xoffset = 0;
11848 6429021 yoffset = 0;
11849 6429021 isTargetOffScreenBmp = true;
11850 }
11851
11852
39/86
✓ Branch 0 taken 2364821 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1130854 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1850 times.
✓ Branch 5 taken 2349855 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 404879 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 1536713 times.
✗ Branch 13 not taken.
✓ Branch 14 taken 2543992 times.
✗ Branch 15 not taken.
✓ Branch 16 taken 5287220 times.
✓ Branch 17 taken 21409189 times.
✓ Branch 18 taken 962949 times.
✓ Branch 19 taken 138747 times.
✓ Branch 20 taken 1558269 times.
✓ Branch 21 taken 163717 times.
✓ Branch 22 taken 9266 times.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 928052 times.
✗ Branch 28 not taken.
✓ Branch 29 taken 4335769 times.
✓ Branch 30 taken 50406 times.
✓ Branch 31 taken 7971 times.
✗ Branch 32 not taken.
✓ Branch 33 taken 148823 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 502 times.
✓ Branch 36 taken 144 times.
✗ Branch 37 not taken.
✓ Branch 38 taken 80910 times.
✓ Branch 39 taken 59816 times.
✗ Branch 40 not taken.
✓ Branch 41 taken 824 times.
✗ Branch 42 not taken.
✓ Branch 43 taken 167483 times.
✓ Branch 44 taken 32636464 times.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✓ Branch 47 taken 855 times.
✓ Branch 48 taken 45504 times.
✗ Branch 49 not taken.
✗ Branch 50 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 53 not taken.
✗ Branch 54 not taken.
✓ Branch 55 taken 1173 times.
✓ Branch 56 taken 1092 times.
✗ Branch 57 not taken.
✗ Branch 58 not taken.
✓ Branch 59 taken 1024 times.
✗ Branch 60 not taken.
✗ Branch 61 not taken.
✓ Branch 62 taken 264439 times.
✗ Branch 63 not taken.
✓ Branch 64 taken 113329 times.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✓ Branch 71 taken 324163 times.
✓ Branch 72 taken 2790 times.
✓ Branch 73 taken 34653 times.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✓ Branch 79 taken 19821648 times.
✗ Branch 80 not taken.
✓ Branch 81 taken 6363 times.
✗ Branch 82 not taken.
✓ Branch 83 taken 906 times.
✗ Branch 84 not taken.
✗ Branch 85 not taken.
98897424 switch(sdci[0])
11853 {
11854 case RECTR:
11855 {
11856 2364821 do_rectr(bmp, sdci, xoffset, yoffset);
11857 }
11858 2364821 break;
11859 case FRAMER:
11860 {
11861 do_framer(bmp, sdci, xoffset, yoffset);
11862 }
11863 break;
11864
11865
11866 case CIRCLER:
11867 {
11868 1130854 do_circler(bmp, sdci, xoffset, yoffset);
11869 }
11870 1130854 break;
11871
11872 case ARCR:
11873 {
11874 do_arcr(bmp, sdci, xoffset, yoffset);
11875 }
11876 break;
11877
11878 case ELLIPSER:
11879 {
11880 1850 do_ellipser(bmp, sdci, xoffset, yoffset);
11881 }
11882 1850 break;
11883
11884 case LINER:
11885 {
11886 2349855 do_liner(bmp, sdci, xoffset, yoffset);
11887 }
11888 2349855 break;
11889
11890 case SPLINER:
11891 {
11892 do_spliner(bmp, sdci, xoffset, yoffset);
11893 }
11894 break;
11895
11896 case PUTPIXELR:
11897 {
11898 404879 do_putpixelr(bmp, sdci, xoffset, yoffset);
11899 }
11900 404879 break;
11901 case PIXELARRAYR:
11902 {
11903 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11904 do_putpixelsr(bmp, i, sdci, xoffset, yoffset);
11905 }
11906 break;
11907
11908 case TILEARRAYR:
11909 {
11910 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11911 do_fasttilesr(bmp, i, sdci, xoffset, yoffset);
11912 }
11913 break;
11914
11915 case LINESARRAY:
11916 {
11917 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11918 do_linesr(bmp, i, sdci, xoffset, yoffset);
11919 }
11920 break;
11921
11922 case COMBOARRAYR:
11923 {
11924 //Z_scripterrlog("Reached case PIXELARRAYR\n");
11925 do_fastcombosr(bmp, i, sdci, xoffset, yoffset);
11926 }
11927 break;
11928
11929
11930
11931 case DRAWTILER:
11932 {
11933 1536713 do_drawtiler(bmp, sdci, xoffset, yoffset);
11934 }
11935 1536713 break;
11936
11937 case DRAWTILECLOAKEDR:
11938 {
11939 do_drawtilecloakedr(bmp, sdci, xoffset, yoffset);
11940 }
11941 break;
11942
11943 case DRAWCOMBOR:
11944 {
11945 2543992 do_drawcombor(bmp, sdci, xoffset, yoffset);
11946 }
11947 2543992 break;
11948
11949 case DRAWCOMBOCLOAKEDR:
11950 {
11951 do_drawcombocloakedr(bmp, sdci, xoffset, yoffset);
11952 }
11953 break;
11954
11955 case FASTTILER:
11956 {
11957 5287220 do_fasttiler(bmp, sdci, xoffset, yoffset);
11958 }
11959 5287220 break;
11960
11961 case FASTCOMBOR:
11962 {
11963 21409189 do_fastcombor(bmp, sdci, xoffset, yoffset);
11964 }
11965 21409189 break;
11966
11967 case DRAWCHARR:
11968 {
11969 962949 do_drawcharr(bmp, sdci, xoffset, yoffset);
11970 }
11971 962949 break;
11972
11973 case DRAWINTR:
11974 {
11975 138747 do_drawintr(bmp, sdci, xoffset, yoffset);
11976 }
11977 138747 break;
11978
11979 case DRAWSTRINGR:
11980 {
11981 1558269 do_drawstringr(bmp, i, sdci, xoffset, yoffset);
11982 }
11983 1558269 break;
11984
11985 case DRAWSTRINGR2:
11986 {
11987 163717 do_drawstringr2(bmp, i, sdci, xoffset, yoffset);
11988 }
11989 163717 break;
11990
11991 case QUADR:
11992 {
11993 9266 do_drawquadr(bmp, sdci, xoffset, yoffset);
11994 }
11995 9266 break;
11996
11997 case QUAD3DR:
11998 {
11999 do_drawquad3dr(bmp, i, sdci, xoffset, yoffset);
12000 }
12001 break;
12002
12003 case TRIANGLER:
12004 {
12005 do_drawtriangler(bmp, sdci, xoffset, yoffset);
12006 }
12007 break;
12008
12009 case TRIANGLE3DR:
12010 {
12011 do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset);
12012 }
12013 break;
12014
12015 case POLYGONR:
12016 {
12017 do_polygonr(bmp, i, sdci, xoffset, yoffset);
12018 }
12019 break;
12020
12021
12022 case BITMAPR:
12023 {
12024 928052 do_drawbitmapr(bmp, sdci, xoffset, yoffset);
12025 }
12026 928052 break;
12027
12028 case BITMAPEXR:
12029 {
12030 do_drawbitmapexr(bmp, sdci, xoffset, yoffset);
12031 }
12032 break;
12033
12034 case DRAWLAYERR:
12035 {
12036 4335769 do_drawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12037 }
12038 4335769 break;
12039
12040 case DRAWSCREENR:
12041 {
12042 50406 do_drawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp);
12043 }
12044 50406 break;
12045
12046 7971 case BMPRECTR: bmp_do_rectr(bmp, sdci, xoffset, yoffset); break;
12047 case BMPFRAMER: bmp_do_framer(bmp, sdci, xoffset, yoffset); break;
12048 148823 case BMPCIRCLER: bmp_do_circler(bmp, sdci, xoffset, yoffset); break;
12049 case BMPARCR: bmp_do_arcr(bmp, sdci, xoffset, yoffset); break;
12050 502 case BMPELLIPSER: bmp_do_ellipser(bmp, sdci, xoffset, yoffset); break;
12051 144 case BMPLINER: bmp_do_liner(bmp, sdci, xoffset, yoffset); break;
12052 case BMPSPLINER: bmp_do_spliner(bmp, sdci, xoffset, yoffset); break;
12053 80910 case BMPPUTPIXELR: bmp_do_putpixelr(bmp, sdci, xoffset, yoffset); break;
12054 59816 case BMPDRAWTILER: bmp_do_drawtiler(bmp, sdci, xoffset, yoffset); break;
12055 case BMPDRAWTILECLOAKEDR: bmp_do_drawtilecloakedr(bmp, sdci, xoffset, yoffset); break;
12056 824 case BMPDRAWCOMBOR: bmp_do_drawcombor(bmp, sdci, xoffset, yoffset); break;
12057 case BMPDRAWCOMBOCLOAKEDR: bmp_do_drawcombocloakedr(bmp, sdci, xoffset, yoffset); break;
12058 167483 case BMPFASTTILER: bmp_do_fasttiler(bmp, sdci, xoffset, yoffset); break;
12059 32636464 case BMPFASTCOMBOR: bmp_do_fastcombor(bmp, sdci, xoffset, yoffset); break;
12060 case BMPDRAWCHARR: bmp_do_drawcharr(bmp, sdci, xoffset, yoffset); break;
12061 case BMPDRAWINTR: bmp_do_drawintr(bmp, sdci, xoffset, yoffset); break;
12062 855 case BMPDRAWSTRINGR: bmp_do_drawstringr(bmp, i, sdci, xoffset, yoffset); break;
12063 45504 case BMPDRAWSTRINGR2: bmp_do_drawstringr2(bmp, i, sdci, xoffset, yoffset); break;
12064 case BMPQUADR: bmp_do_drawquadr(bmp, sdci, xoffset, yoffset); break;
12065 case BMPQUAD3DR: bmp_do_drawquad3dr(bmp, i, sdci, xoffset, yoffset); break;
12066
12067 case BITMAPGETPIXEL: bmp_do_getpixelr(bmp, sdci, xoffset, yoffset); break;
12068 case BMPTRIANGLER: bmp_do_drawtriangler(bmp, sdci, xoffset, yoffset); break;
12069 case BMPTRIANGLE3DR: bmp_do_drawtriangle3dr(bmp, i, sdci, xoffset, yoffset); break;
12070 case BMPPOLYGONR: bmp_do_polygonr(bmp, i, sdci, xoffset, yoffset); break;
12071 1173 case BMPDRAWLAYERR: do_bmpdrawlayerr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12072 1092 case BMPDRAWSCREENR: do_bmpdrawscreenr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12073 case BMPDRAWSCREENSOLIDR: do_bmpdrawscreen_solidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12074 case BMPDRAWSCREENSOLID2R: do_bmpdrawscreen_solidr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12075 1024 case BMPDRAWSCREENCOMBOFR: do_bmpdrawscreen_cflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12076 case BMPDRAWSCREENCOMBOIR: do_bmpdrawscreen_ciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12077 case BMPDRAWSCREENCOMBOTR: do_bmpdrawscreen_ctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12078 264439 case BMPBLIT: bmp_do_drawbitmapexr(bmp, sdci, xoffset, yoffset); break;
12079 case BMPMODE7: bmp_do_mode7r(bmp, sdci, xoffset, yoffset); break;
12080 113329 case BMPBLITTO: bmp_do_blittor(bmp, sdci, xoffset, yoffset); break;
12081 case TILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, false, "TileBlit()"); break;
12082 case COMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, false); break;
12083 case BMPTILEBLIT: do_tileblit(bmp, sdci, xoffset, yoffset, true, "TileBlit()"); break;
12084 case BMPCOMBOBLIT: do_comboblit(bmp, sdci, xoffset, yoffset, true); break;
12085 case READBITMAP: bmp_do_readr(bmp, i, sdci, xoffset, yoffset); break;
12086 case WRITEBITMAP: bmp_do_writer(bmp, i, sdci, xoffset, yoffset); break;
12087 324163 case CLEARBITMAP: bmp_do_clearr(bmp, sdci, xoffset, yoffset); break;
12088 2790 case BITMAPCLEARTOCOLOR: bmp_do_clearcolorr(bmp, sdci, xoffset, yoffset); break;
12089 34653 case REGENERATEBITMAP: bmp_do_regenr(bmp, sdci, xoffset, yoffset); break;
12090
12091 case BMPDRAWLAYERSOLIDR: do_bmpdrawlayersolidmaskr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12092 case BMPDRAWLAYERCFLAGR: do_bmpdrawlayercflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12093 case BMPDRAWLAYERCTYPER: do_bmpdrawlayerctyper(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12094 case BMPDRAWLAYERCIFLAGR: do_bmpdrawlayerciflagr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12095 case BMPDRAWLAYERSOLIDITYR: do_bmpdrawlayersolidityr(bmp, sdci, xoffset, yoffset, isTargetOffScreenBmp); break;
12096 19821648 case BMPWRITETILE: do_bmpwritetile(bmp, sdci, xoffset, yoffset); break;
12097 case BMPDITHER: do_bmpdither(bmp, sdci, xoffset, yoffset); break;
12098 6363 case BMPREPLCOLOR: do_bmpreplcol(bmp, sdci, xoffset, yoffset); break;
12099 case BMPSHIFTCOLOR: do_bmpshiftcol(bmp, sdci, xoffset, yoffset); break;
12100 906 case BMPMASKDRAW: do_bmpmaskdraw(bmp, sdci, xoffset, yoffset); break;
12101 case BMPMASKBLIT: do_bmpmaskblit(bmp, sdci, xoffset, yoffset); break;
12102 }
12103 98897424 }
12104
12105
12106 3207885 color_map=&trans_table;
12107 398566646 }
12108
12109 16067707 void CScriptDrawingCommands::Clear()
12110 {
12111 16067707 scb.update();
12112 16067707 dirty_layers.clear();
12113
2/2
✓ Branch 0 taken 11437426 times.
✓ Branch 1 taken 4630281 times.
16067707 if(commands.empty())
12114 11437426 return;
12115
12116 //only clear what was used.
12117 4630281 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12118 4630281 count = 0;
12119
12120 4630281 draw_container.Clear();
12121 16067707 }
12122 CScriptDrawingCommands* CScriptDrawingCommands::pop_commands()
12123 {
12124 CScriptDrawingCommands* ret = new CScriptDrawingCommands();
12125 if(commands.empty())
12126 return ret;
12127 ret->push_commands(this, false);
12128
12129 memset((void*)&commands[0], 0, count * sizeof(CScriptDrawingCommandVars));
12130 count = 0;
12131
12132 draw_container.Clear();
12133 return ret;
12134 }
12135 void CScriptDrawingCommands::push_commands(CScriptDrawingCommands* other, bool del)
12136 {
12137 commands.insert(commands.end(), other->commands.begin(), other->commands.end());
12138 count += other->count;
12139 if(del) delete other;
12140 }
12141
12142 148956 void do_script_draws(BITMAP *targetBitmap, mapscr* theScreen, int32_t xoff, int32_t yoff, bool hideLayer7)
12143 {
12144
2/2
✓ Branch 0 taken 147962 times.
✓ Branch 1 taken 994 times.
148956 if(XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
12145
2/2
✓ Branch 0 taken 147138 times.
✓ Branch 1 taken 1818 times.
148956 if(XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
12146 148956 do_primitives(targetBitmap, 0, theScreen, xoff, yoff);
12147 148956 do_primitives(targetBitmap, 1, theScreen, xoff, yoff);
12148
2/2
✓ Branch 0 taken 994 times.
✓ Branch 1 taken 147962 times.
148956 if(!XOR(theScreen->flags7&fLAYER2BG, DMaps[currdmap].flags&dmfLAYER2BG)) do_primitives(targetBitmap, 2, theScreen, xoff, yoff);
12149
2/2
✓ Branch 0 taken 1818 times.
✓ Branch 1 taken 147138 times.
148956 if(!XOR(theScreen->flags7&fLAYER3BG, DMaps[currdmap].flags&dmfLAYER3BG)) do_primitives(targetBitmap, 3, theScreen, xoff, yoff);
12150 148956 do_primitives(targetBitmap, 4, theScreen, xoff, yoff);
12151 148956 do_primitives(targetBitmap, 5, theScreen, xoff, yoff);
12152 148956 do_primitives(targetBitmap, 6, theScreen, xoff, yoff);
12153
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 148956 times.
148956 if(!hideLayer7) do_primitives(targetBitmap, 7, theScreen, xoff, yoff);
12154 148956 }
12155